Relational Active record with BELONGS_TO in Yii
I have 2 tables called Member
and MemberResume
.
MemberResume
references Member
on the key memberid
.
In the MemberResume
model the relation is set like this:
'member' => array(self::BELONGS_TO, 'Member', 'memberid')
I am trying to create a model in this manner.
$model=Memberresume::model()->with('member')->findAllByAttributes(array('memberid'=>$id));
But in the model I am not able to access the开发者_运维技巧 attributes of member
table like membername
etc., though the relational query generated seems to consider the relationship.
Any idea why?
Try this instead:
$model=Memberresume::model()->findAllByAttributes(
array('memberid'=>$id), // $attributes
array('with'=>'member') // $condition (string, array or Criteria object, I think)
);
findAllByAttributes accepts a second "condition" parameter you can add your "with" clause to. Doing it this way should join the Member table so you can access it's attributes.
try to $model =Memberresume::model()->findByPk(1);
var_dump($model->member);
精彩评论