import the models from the module in the config file then override the relations function in both the models
for example
//main.php
....
'import'=>array(
'application.models.*',
'application.components.*',
'application.modules.user.models.*',
),
....
//in the Order model
...
public function relations()
{
// NOTE: you may need to adjust the relation name and the related
// class name for the relations automatically generated below.
return array(
'getUser' => array(self::BELONGS_TO, 'User', 'user_id'),
);
}
....
// then in the User model
...
public function relations()
{
// NOTE: you may need to adjust the relation name and the related
// class name for the relations automatically generated below.
return array(
'orders' => array(self::HAS_MANY, 'Order', 'user_id'),
);
}
..
actually i have the relation set. My problem is that i have order -> user -> profiles fields.
I mean, if anyone has used the yii-user module, it has profile fields where you can define dynamically your own fields. So, i have created some of them, but in code i dont know how to access them…
public function getNombre()
{
$cmd = Yii::app()->db->createCommand('SELECT nombre
FROM profiles
WHERE user_id = :idUser')->bindValues(array(':idUser'=>$this->FKUser));
$resultado = $cmd->queryAll();
foreach($resultado as $row){
$nombre = $row['nombre'];
}
return $nombre;
}
So ‘Order’ BELONGS_TO ‘User’ … this is written in your Order model.
And ‘User’ HAS_ONE ‘Profile’ … this is written in User model of yii-user.
When the Profile model has an attribute named ‘phone’, then you can access it by the notation of
$order->user->profile->phone
Of course, ‘phone’ must exist as an attribute of Profile. When you have deleted or renamed it, then the code above will not work.
Well, this is a very simple solution but you might think it dirty and unstable, because the attributes of Profile can be dynamically changed.
But, after all, I think the dynamic nature of yii-user’s profiles is for the developers, not for the end users. A developer can get them under his control, and he should.