I think that is a good idea to add another table, because the number of units is limited.
You can find meny threads about a four table relation. It's difficult to make a select query for it, but if you add a model for the connecting table it becomes simple. You already have an id in the ingredient_recipe table. Make a model for that table.
You will be able to eager load them simply.
Recipe::find($id)->with('connectors', 'connectors.ingredient', 'connectors.unit');
Thanks for your reply!
I'm not sure if I understood right ...
Is that right?
Sorry but I'm a bit confused ... i've never seen a model for a pivot table or something like that so I don't know how to go about that... I'm relatively new to laravel and I would appreciate some kind of help a lot! event if it's a good read or something like that :) ...
Thanks!
You misunderstood me.
The only table you will add is your units table. Nothing else. The char(50) unit column in the existing pivot table should be changed into an integer as foreign key (unit_id). That table will connect al three models at the same time. The 'Connector' I am talking about should be an 'Ingredient_Recipe' model.
Ther relationships you described are good.
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community