Many to many relation, with informations

Hi all,

While creating a private message system in a community script, I defined this relation, in the User model class:

'privateMessages'=>array(self::MANY_MANY, 'PrivateMessage', 'rel_privateMessagesReceivers(userId, privateMessagesId)',

	'condition' => 'deleted = 0'


It works great, but I want to do a little more. In the “rel_privateMessagesReceivers” table, I have another column; ‘opened’, which specifies if the user has opened the message or not. When i loop through a users messages, i want that information to be available, but how do i collect or edit it, through the mentioned relation above?

And: what is the correct way of creating a new relation between objects? I’ve been looking for something like $user->relate(‘privateMessages’, $messageObject), but I couldn’t find any similar functions.

Thanks in advance!

There is no way to use info from bound table right now (except extra SQL queries maybe). We are going to support this in the next Yii versions.

Okay, so what to do right now?

Extra SQL query like:

$post->tag = PostTag::model()->findByPk(array(array(

  'post_id' => $post->id,

  'tag_id' => $tag->id,


There are also some workarounds: