Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Many-to-Many Relation Deleting Procedure
  • Dear,

    i have found the cascade deletion very help full in belong to,has one, has many.

    but in many to many what exactly happening

    does it delete the child entry or delete the entry in relation table?
  • HarroHarro
    Accepted Answer
    A cascade_delete = true will delete the related objects, that is true for all relation types.

    If in a many_many casade_delete is false, it will only delete the records in the through-table, effectively disconnecting the two related objects.

    For this reason a cascade delete in a many_many is almost never used, since basically you're relating two "parent" type objects.
  • i have another trouble now.

    Students table and awards table are in many-many relation, linked with students_awards

    here, i have used soft delete, when i delete students, it deletes soft all child of it, all childs linked by has many, has one. .... in many many, it breaks the link automatically, good.

    but at restore, it restore all has many, has one... automatically, it is also good, but it cant resote many many relation, Any bug? or any hidden options.?

    Any way to impliment it
  • I don't think that is supported, but I'm not an ORM expert, you might want to ping "uru" on IRC.
  • I'm not uru but I have been working a lot with the ORM (I kinda dig it). However, as far as I know the ORM and its source code: your requested feature is not supported that is for many-many soft-deletes, there is no flag that actually marks the entries on the joint-table as "old" or deleted. Thus, once the relation is gone, it's gone.

    However, it shouldn't be too difficult to find a solution, since the joint-table row must only be deleted when the last child is purged and updated to the correct ID when an item is soft-deleted.

    Nevertheless, you might want to hit "uru" on IRC since he's the main maintainer of ORM and knows the code best.
  • What I don't understand:

    If you delete child records, they will be soft-deleted, correct? So why would the join-table records be gone, as the records they point to still exist?

    Or is it that the soft-delete operation itself deletes the join-table records? If that is the case, it is indeed not supported at the moment.
  • According to my concept, The Entry is only soft deleted, exactly not deleted from db, so the link table entries should not be deleted. But now it is deleting, any way to fix it. any body know?
  • As Philip already wrote, I don't think it's supported at the moment.

    And I don't think it something "uru" will want to add, it is very complex (which is probably the reason it is not supported), but you might want to ask him on IRC.

Howdy, Stranger!

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

In this Discussion