Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
ORM multiple updates
  • In the documentation it shows an example of one record being updated. It is possible to update multiple records from an ORM query? Essentially what I'm trying to do is read x amount of records from the DB and them mark them as processed.
    Just wondered if there was a quick ORM method, or whether I had to use the standard DB class?
  • No, there isn't. An ORM works with objects, where every object represents a row in a database table. This implies you will have to iterate over the objects retrieved in a query, and save them one at the time. The ORM does update related records on a save() if you have enabled cascading saves. So if the objects in question have a common parent, you can fetch the parent, all it's children, update the child objects, and save the parent. That will automatically also update all children. It will still do it one at the time though, the first rule still applies. If you're looking for an "UPDATE this WHERE that", use the DB class. It's perfectly fine to use that in an ORM model method, the ORM itself also utilizes the DB class to run it's queries.
  • had the same problem and found this clear answer :)
    however i still think it would be better if i can just write Model_xyz::find()->where(...)->update(...);
    and in the underneath it generates the update query and run it once instead of looping
    not sure if this is possible though :)
  • This is programming, so everything is possible. ;-)

    Whether or not is makes sense to make it is another question. An ORM is simply not meant or designed for batch or bulk operations.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion