samdark / yii2-cookbook

Yii 2.0 Community Cookbook
1.45k stars 297 forks source link

Best way to deal with junction table and its extra columns #131

Open bpbastos opened 7 years ago

bpbastos commented 7 years ago

Would be nice a recipe about this subject.

samdark commented 7 years ago

What do you want to do with it?

bpbastos commented 7 years ago

It was a suggestion of recipe to be included in the cookbook. Sorry if I created it in the wrong place.

samdark commented 7 years ago

No, it's correct place. I've asked because I want to understand your use case to get a better recipe.

bpbastos commented 7 years ago

Nice! It's a common problem, unfortunately I haven't found a good way of dealing with this without being too much complex. I've found a good article: http://future500.nl/articles/2013/09/doctrine-2-how-to-handle-join-tables-with-extra-columns/ maybe someone can migrate it to yii2.

samdark commented 7 years ago

In general, you need to create a model for that junction table and use it via relations.