How to use a Magento 1 model to update multiple rows?Update magento attribute field based on value from a 'custom' tableHow do I Create one Magento Product with 40 different types of Fabrics to choose from?Managing Multiple Magento StoresProgramatically update customer address by its entity idHow To Fetch And Display Last 4 Table Rows?how to add customer attribute with default values set for all existing entities?How to use SQL in Magento modulesMagento, I only need one data in databaseGetting current request page sizeHow can I use partial (code block) in multiple templates?

How can I be pwned if I'm not registered on the compromised site?

Are Wave equations equivalent to Maxwell equations in free space?

Integrating function with /; in its definition

Replacing tantalum capacitor with ceramic capacitor for Op Amps

Professor forcing me to attend a conference

What is Tony Stark injecting into himself in Iron Man 3?

I can't die. Who am I?

Where is the fallacy here?

Are there other characters in the Star Wars universe who had damaged bodies and needed to wear an outfit like Darth Vader?

Why aren't there more gauls like Obelix?

Affine transformation of circular arc in 3D

Is divide-by-zero a security vulnerability?

Paper published similar to PhD thesis

Why doesn't "adolescent" take any articles in "listen to adolescent agonising"?

What does it mean when I add a new variable to my linear model and the R^2 stays the same?

What's the best tool for cutting holes into duct work?

Quitting employee has privileged access to critical information

How do you make a gun that shoots melee weapons and/or swords?

Has a sovereign Communist government ever run, and conceded loss, on a fair election?

Using the imperfect indicative vs. subjunctive with si

The (Easy) Road to Code

Why won't the strings command stop?

If nine coins are tossed, what is the probability that the number of heads is even?

How to make sure I'm assertive enough in contact with subordinates?



How to use a Magento 1 model to update multiple rows?


Update magento attribute field based on value from a 'custom' tableHow do I Create one Magento Product with 40 different types of Fabrics to choose from?Managing Multiple Magento StoresProgramatically update customer address by its entity idHow To Fetch And Display Last 4 Table Rows?how to add customer attribute with default values set for all existing entities?How to use SQL in Magento modulesMagento, I only need one data in databaseGetting current request page sizeHow can I use partial (code block) in multiple templates?













2















I am processing some records and I need to set a datetime field to the current time for multiple rows. I have all the row IDs. What's the best way to do this with Magento 1? The SQL would be like this:



update
my_table
set
processed_on = "2015-09-09 11:11:04"
where
id in(34, 56, 77, 39)









share|improve this question




























    2















    I am processing some records and I need to set a datetime field to the current time for multiple rows. I have all the row IDs. What's the best way to do this with Magento 1? The SQL would be like this:



    update
    my_table
    set
    processed_on = "2015-09-09 11:11:04"
    where
    id in(34, 56, 77, 39)









    share|improve this question


























      2












      2








      2








      I am processing some records and I need to set a datetime field to the current time for multiple rows. I have all the row IDs. What's the best way to do this with Magento 1? The SQL would be like this:



      update
      my_table
      set
      processed_on = "2015-09-09 11:11:04"
      where
      id in(34, 56, 77, 39)









      share|improve this question
















      I am processing some records and I need to set a datetime field to the current time for multiple rows. I have all the row IDs. What's the best way to do this with Magento 1? The SQL would be like this:



      update
      my_table
      set
      processed_on = "2015-09-09 11:11:04"
      where
      id in(34, 56, 77, 39)






      magento-1.9 model






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited 7 hours ago







      Ryan

















      asked yesterday









      RyanRyan

      1337




      1337




















          3 Answers
          3






          active

          oldest

          votes


















          0














          To update existing rows in a model, you need to load each row first, call addData() with the new data, then save the row.



          An example would look like this:



          $rowIds = array(1,2,3)
          foreach($rowIds as $rowId)
          $data = array('processed_on' => "2015-09-09 11:11:04");

          $model = Mage::getModel('your_model')->load($rowId)->addData($data);
          try
          $model->setId($rowId)->save();
          echo "Record updated";
          catch (Exception $e)
          echo $e->getMessage();







          share|improve this answer

























          • You should remove setId($id) before calling save() since $id is not defined and the model has already an id, because it is an existent record.

            – HelgeB
            yesterday






          • 1





            You should also vaiud load/delete/save methods inside loops.

            – sv3n
            12 hours ago


















          0














          Instead of load/save inside foreach, you can try this:



          $collection = Mage::getResourceModel('catalog/product_collection')
          ->addIdFilter(array(1,2,3));

          foreach ($collection as $product)
          $product->setProcessedOn('2015-09-09 11:11:04');
          # add this to avoid pricerule update
          $product->setIsMassupdate(true);

          $collection->save();





          share|improve this answer






























            0














            Instead of load/save inside foreach, you can try this:



            $collection = Mage::getModel('your/model')->getCollection()
            ->addIdFilter(array(1,2,3));

            foreach ($collection as $item)
            $item->setProcessedOn('2015-09-09 11:11:04');

            $collection->save();





            share|improve this answer






















              Your Answer








              StackExchange.ready(function()
              var channelOptions =
              tags: "".split(" "),
              id: "479"
              ;
              initTagRenderer("".split(" "), "".split(" "), channelOptions);

              StackExchange.using("externalEditor", function()
              // Have to fire editor after snippets, if snippets enabled
              if (StackExchange.settings.snippets.snippetsEnabled)
              StackExchange.using("snippets", function()
              createEditor();
              );

              else
              createEditor();

              );

              function createEditor()
              StackExchange.prepareEditor(
              heartbeatType: 'answer',
              autoActivateHeartbeat: false,
              convertImagesToLinks: false,
              noModals: true,
              showLowRepImageUploadWarning: true,
              reputationToPostImages: null,
              bindNavPrevention: true,
              postfix: "",
              imageUploader:
              brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
              contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
              allowUrls: true
              ,
              onDemand: true,
              discardSelector: ".discard-answer"
              ,immediatelyShowMarkdownHelp:true
              );



              );













              draft saved

              draft discarded


















              StackExchange.ready(
              function ()
              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f264758%2fhow-to-use-a-magento-1-model-to-update-multiple-rows%23new-answer', 'question_page');

              );

              Post as a guest















              Required, but never shown

























              3 Answers
              3






              active

              oldest

              votes








              3 Answers
              3






              active

              oldest

              votes









              active

              oldest

              votes






              active

              oldest

              votes









              0














              To update existing rows in a model, you need to load each row first, call addData() with the new data, then save the row.



              An example would look like this:



              $rowIds = array(1,2,3)
              foreach($rowIds as $rowId)
              $data = array('processed_on' => "2015-09-09 11:11:04");

              $model = Mage::getModel('your_model')->load($rowId)->addData($data);
              try
              $model->setId($rowId)->save();
              echo "Record updated";
              catch (Exception $e)
              echo $e->getMessage();







              share|improve this answer

























              • You should remove setId($id) before calling save() since $id is not defined and the model has already an id, because it is an existent record.

                – HelgeB
                yesterday






              • 1





                You should also vaiud load/delete/save methods inside loops.

                – sv3n
                12 hours ago















              0














              To update existing rows in a model, you need to load each row first, call addData() with the new data, then save the row.



              An example would look like this:



              $rowIds = array(1,2,3)
              foreach($rowIds as $rowId)
              $data = array('processed_on' => "2015-09-09 11:11:04");

              $model = Mage::getModel('your_model')->load($rowId)->addData($data);
              try
              $model->setId($rowId)->save();
              echo "Record updated";
              catch (Exception $e)
              echo $e->getMessage();







              share|improve this answer

























              • You should remove setId($id) before calling save() since $id is not defined and the model has already an id, because it is an existent record.

                – HelgeB
                yesterday






              • 1





                You should also vaiud load/delete/save methods inside loops.

                – sv3n
                12 hours ago













              0












              0








              0







              To update existing rows in a model, you need to load each row first, call addData() with the new data, then save the row.



              An example would look like this:



              $rowIds = array(1,2,3)
              foreach($rowIds as $rowId)
              $data = array('processed_on' => "2015-09-09 11:11:04");

              $model = Mage::getModel('your_model')->load($rowId)->addData($data);
              try
              $model->setId($rowId)->save();
              echo "Record updated";
              catch (Exception $e)
              echo $e->getMessage();







              share|improve this answer















              To update existing rows in a model, you need to load each row first, call addData() with the new data, then save the row.



              An example would look like this:



              $rowIds = array(1,2,3)
              foreach($rowIds as $rowId)
              $data = array('processed_on' => "2015-09-09 11:11:04");

              $model = Mage::getModel('your_model')->load($rowId)->addData($data);
              try
              $model->setId($rowId)->save();
              echo "Record updated";
              catch (Exception $e)
              echo $e->getMessage();








              share|improve this answer














              share|improve this answer



              share|improve this answer








              edited 15 hours ago

























              answered yesterday









              MClaudioMClaudio

              162




              162












              • You should remove setId($id) before calling save() since $id is not defined and the model has already an id, because it is an existent record.

                – HelgeB
                yesterday






              • 1





                You should also vaiud load/delete/save methods inside loops.

                – sv3n
                12 hours ago

















              • You should remove setId($id) before calling save() since $id is not defined and the model has already an id, because it is an existent record.

                – HelgeB
                yesterday






              • 1





                You should also vaiud load/delete/save methods inside loops.

                – sv3n
                12 hours ago
















              You should remove setId($id) before calling save() since $id is not defined and the model has already an id, because it is an existent record.

              – HelgeB
              yesterday





              You should remove setId($id) before calling save() since $id is not defined and the model has already an id, because it is an existent record.

              – HelgeB
              yesterday




              1




              1





              You should also vaiud load/delete/save methods inside loops.

              – sv3n
              12 hours ago





              You should also vaiud load/delete/save methods inside loops.

              – sv3n
              12 hours ago













              0














              Instead of load/save inside foreach, you can try this:



              $collection = Mage::getResourceModel('catalog/product_collection')
              ->addIdFilter(array(1,2,3));

              foreach ($collection as $product)
              $product->setProcessedOn('2015-09-09 11:11:04');
              # add this to avoid pricerule update
              $product->setIsMassupdate(true);

              $collection->save();





              share|improve this answer



























                0














                Instead of load/save inside foreach, you can try this:



                $collection = Mage::getResourceModel('catalog/product_collection')
                ->addIdFilter(array(1,2,3));

                foreach ($collection as $product)
                $product->setProcessedOn('2015-09-09 11:11:04');
                # add this to avoid pricerule update
                $product->setIsMassupdate(true);

                $collection->save();





                share|improve this answer

























                  0












                  0








                  0







                  Instead of load/save inside foreach, you can try this:



                  $collection = Mage::getResourceModel('catalog/product_collection')
                  ->addIdFilter(array(1,2,3));

                  foreach ($collection as $product)
                  $product->setProcessedOn('2015-09-09 11:11:04');
                  # add this to avoid pricerule update
                  $product->setIsMassupdate(true);

                  $collection->save();





                  share|improve this answer













                  Instead of load/save inside foreach, you can try this:



                  $collection = Mage::getResourceModel('catalog/product_collection')
                  ->addIdFilter(array(1,2,3));

                  foreach ($collection as $product)
                  $product->setProcessedOn('2015-09-09 11:11:04');
                  # add this to avoid pricerule update
                  $product->setIsMassupdate(true);

                  $collection->save();






                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered 12 hours ago









                  sv3nsv3n

                  9,85262355




                  9,85262355





















                      0














                      Instead of load/save inside foreach, you can try this:



                      $collection = Mage::getModel('your/model')->getCollection()
                      ->addIdFilter(array(1,2,3));

                      foreach ($collection as $item)
                      $item->setProcessedOn('2015-09-09 11:11:04');

                      $collection->save();





                      share|improve this answer



























                        0














                        Instead of load/save inside foreach, you can try this:



                        $collection = Mage::getModel('your/model')->getCollection()
                        ->addIdFilter(array(1,2,3));

                        foreach ($collection as $item)
                        $item->setProcessedOn('2015-09-09 11:11:04');

                        $collection->save();





                        share|improve this answer

























                          0












                          0








                          0







                          Instead of load/save inside foreach, you can try this:



                          $collection = Mage::getModel('your/model')->getCollection()
                          ->addIdFilter(array(1,2,3));

                          foreach ($collection as $item)
                          $item->setProcessedOn('2015-09-09 11:11:04');

                          $collection->save();





                          share|improve this answer













                          Instead of load/save inside foreach, you can try this:



                          $collection = Mage::getModel('your/model')->getCollection()
                          ->addIdFilter(array(1,2,3));

                          foreach ($collection as $item)
                          $item->setProcessedOn('2015-09-09 11:11:04');

                          $collection->save();






                          share|improve this answer












                          share|improve this answer



                          share|improve this answer










                          answered 12 hours ago









                          sv3nsv3n

                          9,85262355




                          9,85262355



























                              draft saved

                              draft discarded
















































                              Thanks for contributing an answer to Magento Stack Exchange!


                              • Please be sure to answer the question. Provide details and share your research!

                              But avoid


                              • Asking for help, clarification, or responding to other answers.

                              • Making statements based on opinion; back them up with references or personal experience.

                              To learn more, see our tips on writing great answers.




                              draft saved


                              draft discarded














                              StackExchange.ready(
                              function ()
                              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f264758%2fhow-to-use-a-magento-1-model-to-update-multiple-rows%23new-answer', 'question_page');

                              );

                              Post as a guest















                              Required, but never shown





















































                              Required, but never shown














                              Required, but never shown












                              Required, but never shown







                              Required, but never shown

































                              Required, but never shown














                              Required, but never shown












                              Required, but never shown







                              Required, but never shown







                              Popular posts from this blog

                              Nidaros erkebispedøme

                              Birsay

                              Where did Arya get these scars? Unicorn Meta Zoo #1: Why another podcast? Announcing the arrival of Valued Associate #679: Cesar Manara Favourite questions and answers from the 1st quarter of 2019Why did Arya refuse to end it?Has the pronunciation of Arya Stark's name changed?Has Arya forgiven people?Why did Arya Stark lose her vision?Why can Arya still use the faces?Has the Narrow Sea become narrower?Does Arya Stark know how to make poisons outside of the House of Black and White?Why did Nymeria leave Arya?Why did Arya not kill the Lannister soldiers she encountered in the Riverlands?What is the current canonical age of Sansa, Bran and Arya Stark?