Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
How to put into and get from through table with many_many ralation?
Didn't find if anybody ask this question earlier... Seemed, this operation is usual enough to interesting for it.
Ok. I have two tables: the 'vegetables' and the 'orders', it has many-to-many relation through the 'orders_vegetables' and contains some one field 'amount'.
I created models Model_Order and Model_Vegetable and set _many_many properites accordingly.
I want to set a value of the 'amount' field, when I create the order with set of vegetables. And I naturally want to read a value of the 'amount' field, when I select the certain vegetable in the certain order.
I would want that it was like this:
$order = Model_Order::find($order_id);
But only the way that seems right is to create one more model: Model_Ordervegetable and set two has_many relations for both tables... I have not tried this yet, but decided first to ask for correct solution as designed, if it did...
Offtopic: My wife always say to me: "Don't build complex compound sentences in English or don't be surprised then, if anyone did not understand you"
If you have attributes in your through table, it's not a through table anymore, you have just created two one-to-many relations using three tables.
And yes, that would require a third model.
Note that you can have both relations active at the same time.
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