Hello all,
I am fairly new to yii and would appreciate any help with the following thing:
I am trying to execute an eager approach query but keep getting a CDbException that reads:
The relation "role" in active record class "Member" is specified with an invalid foreign key. The format of the foreign key must be "joinTable(fk1,fk2,...)".
The tables involved here are :
member
±---------±----------±-----------±---------±---------------±-------±-------------±---------±-----------±---------+
| ID | FirstName | MiddleName | LastName | SecondLastName | Gender | UserName | Password | DateJoined | DateLeft |
±---------±----------±-----------±---------±---------------±-------±-------------±---------±-----------±---------+
role
±—±---------±---------±---------±--------------------+
| ID | MemberID | RecordID | RoleType | DateInserted |
±—±---------±---------±---------±--------------------+
These are my relation function inside their respective classes:
Member
public function relations()
{
// NOTE: you may need to adjust the relation name and the related
// class name for the relations automatically generated below.
return array(
'role' => array(self::MANY_MANY,'Role','MemberID'),
'record'=> array(self::MANY_MANY,'Record','MemberID'),
);
}
Role
public function relations()
{
// NOTE: you may need to adjust the relation name and the related
// class name for the relations automatically generated below.
return array(
'member' =>array(self::BELONGS_TO,'Member','MemberID'),
'record' =>array(self::BELONGS_TO,'Record','RecordID'),
'relationship'=>array(self::HAS_MANY,'Relationship',array('RelationshipID'=>'id'),'through'=>'Relationship_Involves_Role'),
);
}
When executing this:
$userCredentials = Member::model()->with('role')->findAll();
I get the error mentioned above.
Any ideas why this is happening?