开发者

Relational Active record with BELONGS_TO in Yii

开发者 https://www.devze.com 2023-01-28 23:15 出处:网络
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:

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);

0

精彩评论

暂无评论...
验证码 换一张
取 消