How to create related records with Doctrine PHP

STOODOserbves

New Member
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 :\[code\]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')); }}\[/code\]And\[code\]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')); }}\[/code\]I'm trying to use it by doing something like that :\[code\]$user = new User();$user->save();$conversation = new Conversation();$conversation->users[] = $user;$conversation->save();\[/code\]But it's not working, my junction table "UserConversation" stays empty... Am I doing it the right way? Thank you for your answer,Martin
 
Back
Top