Hello
I have modeled two classes with a many to many relationship : User and Conversation, and I can't create a the link between these two classes when I use them :
class User extends Doctrine_Record
{
public function setTableDefinition() {
$this->hasColumn('udid', 'string', 255);
$this->hasColumn('nb_requetes', 'integer', 255);
}
public function setUp() {
$this->actAs('Timestampable');
$this->hasMany('Conversation as Conversations',
array('local'=> 'user_id',
foreign'=> 'conversation_id',
'refClass' => 'UserConversation'));
}
}
And
class Conversation extends Doctrine_Record
{
public function setTableDefinition() {
$this->setTableName('conversations');
$this->hasColumn('initiator_id', 'integer', 20);
$this->hasColumn('responder_id', 'integer', 20);
}
public function setUp() {
$this->actAs('Timestampable');
$this->hasMany('User as Users',
array('local' => 'conversation_id',
'foreign' => 'user_id',
'refClass' => 'UserConversation'));
}
}
I'm trying to use it by doing something like that :
$user = new User();
$user->save();
$conversation = new Conversation();
$conversation->users[] = $user;
$conversation->save();
But it's not working, my junction table "UserConversation" stays empty... Am I doing it the right way?
Thank you for your answer,
Martin