I’m trying to wrap my mind around how the relations() method works. For instance, in the Yii Guide (Relational Active Record
), this example is given for a MANY_MANY relationship in the Post model:
‘categories’=>array(self::MANY_MANY, ‘Category’, ‘tbl_post_category(post_id, category_id)’),
How is Yii creating this relationship? Is the method getting category_id’s from the Category model where the category_id exists in the tbl_post_category only after filtering on post_id? I’m pretty sure it’s doing this, but I don’t understand how. In the Post table referenced in the guide, the ID field is named “ID”, not post_id. All I can guess is that Yii is looking at the underlying SQL relationships to do the actual linking. Then again, the Guide states:
"it is recommended that primary-foreign key constraints are declared for tables that need to be joined"
Not required.