I’ve read it several times today, and my example is quoted from the guide.
class User extends CActiveRecord
{ ......
public function relations()
{
return array('posts'=>array(self::HAS_MANY, 'Post', 'author_id'),
'profile'=>array(self::HAS_ONE, 'Profile', 'owner_id'), );
}
}
Your answer is clear to me, but I am confused again when look at the following code.
When it defines the relationship from User to Post, why the foreign key is still ‘author_id’ in the Post table? Why not ‘id’ in the User table?
Can I say the foreign key in a relationship, no matter from User to Post, or Post to User, should always be the key that refers to the PK in the other table?