Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
ORM Soft delete
  • Hi everyone,

    I have a relationship between two models, one of them has a "has_many" relation and the other one has a "belongs_to" relation. So, when I run a delete on the model with "has_many" relation all of his children are softdeleted. I'd like to know if the children are deleted one by one or is it created a query that deletes all children in one single action like 'Delete from'.
    The "has_many" relation has a bunch of children and deleting one by one can take a long time to execute.

    I wonder if there is a way to delete all children without being one by one. 
  • HarroHarro
    Accepted Answer
    In general the ORM operates on objects, the relation is not aware of other objects, so optimisations in this area is going to be complex.

    Having said that, I've never used Model_Soft myself, but I understand it sets a timestamp to mark the record as soft-deleted, so nothing prevents you from creating a query that does that directly.

    If you do, note that ORM objects are cached, so changes to the database this way will not be reflected in the cached object.
  • Thanks Harro,

    I agree with you, I guess creating a query will be more efficient and will give less work to me (:

Howdy, Stranger!

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

In this Discussion