I’ve been unsuccessfully searching the forum for a way to declare the relations in a model when multiple fields are to be related to the same field in another table.
The fields PM_From and PM_To are values who have a MANY_TO_ONE relation to User_Id.
But I have no idea how to declare those relations in my PM model.
Hopefully one of you can help me.
try make custom table for this. where PM is your PRIMARY KEY.
PMID INT NOT NULL AUTO_INCREMENT ,
Name VARCHAR( 255 ) NOT NULL ,
Value TEXT NOT NULL ,
PRIMARY KEY (
PMID ) ) ENGINE = MYISAM ;
I don’t see where you want to go with this.
The entire database is normalized so normally there shouldn’t be a need for another table to connect both tables.
Maybe it’s helpful to explain what the PM table contains. They are internal messages from one user to another.
The PM_To and PM_From fields are the User_Id of the recipient and sender of the message.
try to read http://www.yiiframework.com/doc/guide/1.1/en/database.arr
Did you try something like this
public function relations()
'sender'=>array(self::BELONGS_TO, 'User', 'PM_From'),
'recipient'=>array(self::BELONGS_TO, 'User', 'PM_To'),
And a query similar to this
$models = PM::model()->with('sender', 'recipient')->findAll();
$models = PM::model()->with('sender', 'recipient')->together()->findAll();
This was not required in Yii 1.0
See info box near the top of this page:
This was changed in 1.1:
Tell us more about what kind of problem you experience?
Are you able to display all records using findAll()?
Obviously you solved it while I composed this message.