according to Relational Active Record, Yii has provided for relation MANY_MANY with 2 foreign key.
i want to know, is there any solution to use MANY_MANY with 3 foreign key?
table_abc (relation between table_a, table_b & table_c)
how can i create an relation between 4 table above?
I’m fairly certain Yii doesn’t provide a solution for a table with 3 FKs (and I don’t even know what it would look like – aside from very intriguing!)
What you could do of course is regard table_abc as multiple MANY_MANY tables in one, meaning you can have
a MANY_MANY b
a MANY_MANY c
b MANY_MANY a
b MANY_MANY c
c MANY_MANY a
c MANY_MANY b
Although this sounds rather tricky to manage. If there is a way to solve your problem using a default database structure I’d seriously consider using it; this sounds like a major headache waiting to happen.
I’d recommend something like this:
a HAS_MANY b through abc
b HAS_MANY a through abc
a HAS_MANY c through abc
but the actual implementation highly depends on your Domain Model.
thanks a lot for your suggestion.
it’s very helpful…
i used both of the suggestion.
i used Many_Many, in case if i don’t want to get any field in relation.
i used Has_Many through, in case if i want to get some filed from relation.