I can use AR relations this way successfully:
[tt]
___ belongs to ___ C
|
A — belongs to — B —|___ belongs to ___ D
[/tt]
(pseudo-code)
// common relations, no problem 'BtoC'=>array(self::BELONGS_TO, 'C', 'FK(C)'), 'BtoD'=>array(self::BELONGS_TO, 'D', 'FK(D)'), // A to B relation, without and with condition 'AtoB'=>array(self::BELONGS_TO, 'B', 'FK('), 'AtoB'=>array(self::BELONGS_TO, 'B', 'FK(', 'condition'=>'t3.Username="'.Yii::app()->user->name.'"'), // call A::model()->with(array('AtoB'=>array('C', 'D')))->findAll();
But if I try the other way around I get the "invalid foreign key" message ("The foreign key does not point to either joining table").
I also tried the Many-Many syntax
[tt]
___ belongs to ___ C
|
B —|___ belongs to ___ D
|
|___ has many ___ A
[/tt]
// common relations, no problem 'BtoC'=>array(self::BELONGS_TO, 'C', 'FK(C)'), 'BtoD'=>array(self::BELONGS_TO, 'D', 'FK(D)'), // B to A relation, I tried these two ways 'BtoA'=>array(self::HAS_MANY, 'A', 'FK(A)'), 'BtoA'=>array(self::HAS_MANY, 'A', 'A(AtoB)'), // call B::model()->with(array('BtoA', 'C', 'D'))->findAll();
What am I doing wrong here?
Also, in the first example, why did I have to replace ??.Username with t3.Username?
/Tommy
Edit: PK —> FK