Post 与 Post_Description共享主键:
Post:
public function relations(){
return array(
'description'=>array(self::HAS_MANY, 'Post_Description', 'post_id'),
);
}
Post_Description:
public function relations() {
return array(
'post'=>array(self::BELONGS_TO, 'Post', 'post_id'),
);
}
单元测试
$post = Post::model()->findByPk(18);
$this->assertNotNull($post->descriotion);
$this->assertEquals($post->description->name, "name"); <------Trying to get property of non-object
望各位指点。