I have an interesting problem, and I can’t seem to fix it using the framework, which limits me in using some of the time-saving features of the framework.
I have four tables that are something along the following.
I want to link the users and companies together through AuthAssignments. Every AuthAssignment row has one and only one AuthItem, and therefore the company_id is implicitly there.
It would be nice if the aliasing of table names in many_many relationships had some consistency so that one could define company_id…
I tried the “with” assocation, and then tried defining the intermediate key for companies as “AuthItem.company_id”, but that predictably didn’t work…
And the system automatically preprends the join table’s alias to the beginning of that string, which means there’s no way to make it associate with another table.
Is there a way to do this? Or prevent Yii from automatically prepending the join table? Or possibly with select, such as "(SELECT AuthItem.company_id AS AuthAssignment.company_id)"?
I’ve been wrestling with this for a while, since it seems like there would be a lot of uses for such flexibility. I’m not an SQL expert, but it seems like there should be some sort of way to structure things such that there’s a consistently accessible syntax to do these complex operations with multiple tables. Ideally, the right solution should scale indefinitely while only making one query. I guess that seems like a lot to ask for, huh? I suppose I’m just generally so pleased with Yii it’s surprising when it doesn’t just work the way I would expect during development.