Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Model_Soft and Many to Many relationship not cooperating.
Hey there guys and gals. I seem to be running into what I think to be a bug with the Model_Soft and the Many to Many relationship.
I'm working on a small website to manage registration for some conventions.
I've got two models where this is an issue: Model_Badge and Model_Transaction. The two are related in a many to many relationship (A Transaction can have multiple Badges, such as a family purchasing badges together, and a Badge can have multiple Transactions, such as upgrading a badge at the door.)
Anyways. I've got both models extending Model_Soft, so that even if the badges are deleted, they'll be able to keep a history of the badges and transactions. (I'm aware a Model_Temporal might work well for this in the future, but right now the Model_Soft is plenty.) I've even got an observer set up to refund a badge if there are transactions associated with it that have been paid with a card.
The problem is this: when I delete the Badge, it removes the pairing with any transactions, effectively orphaning them. Is there something I need to take into account that I'm missing?
I can provide some code samples if needed. It's just a bit late, and thought I'd get this out there before I forgot. Thanks for any assistance you can provide.
I have a temporary solution by overriding the delete() function in Model_Badge with the following:
You'll notice this is just the default code from the Model.php from the ORM package, but I've removed everything that deals with relations.
Just to make sure I understand:
You have a parent-child relation, both models based on Model_Soft. You do
$parent->delete(), which soft-deletes the parent, and resets the foreign key of the associated children on a cascade_delete(), instead of soft_deleting them too?
Close, but not quite. My apologies.
The relationship is Many to Many, so they're more siblings than parent-child. When I go to delete one (in this case, the Badge), the Transaction is deleted or not depending on the cascade settings. This is normal and expected.
The unexpected behavior is that regardless of cascade setting, the link in the in-between table (in this case badges_transactions) is removed. There's no way I can have this process the relations and not delete this row in the table.
Ah, ok. The through-table isn't aware of the "softness" of both parents.
I don't think this is supported, please create a ticket for it at
so Steve can comment on it (Model_Soft is his baby), he knows more about it's internals than I do.
Add a Comment
It looks like you're new here. If you want to get involved, click one of these buttons!
Apply for Membership
↳ Job Board
↳ Installation & Setup
↳ Tips and Tutorials
↳ Code share
In this Discussion