I have the following three tables
-
person (id, name)
-
send_receive(id, from, to, messageID) /* from, to are foreign key of person table; messageID is the foreign key of message table */
-
message (id, messageBody)
in the person AR
public function relations()
{
return array(
'receivedLookup'=>array(self::HAS_MANY, 'sendReceive', 'to')
);
}
But when I run
$result = $personA->receivedLookup
, I got an array of sendReceive AR, since count($result) is 5. My ultimate goal is to get the message body that the person A received. If Yii AR relationship is capable of doing this, how should I define the relationship? and How should I run the AR relationship query?
I’ve read the Guide several times, but still couldn’t figure out. Please help!
Thank you!