Code also available here: http://pastie.org/4308149
My models User and Group share a hasAndBelongsToMany relationship. The
following code create the new user, creates the new group and inserts the
correct entry into the groups_users join table. This tells me, the
relationship is configured correctly and working.
Question: If I want to save more than a single group, e.g. the user is in
three groups, how would I have to modify my code?
public function tryHabtm() {
$this->deleteRecords();
$this->User->set(
array(
'id' => null,
'name'=>'Foo Bar',
'email'=>'[email protected]',
'password'=>'secure',
'password_confirmation'=>'secure',
'role'=>'admin',
'company'=>'CakePHP Inc',
'dealer_number'=>'00001',
'phone'=>'+49 111 222 333',
'status'=>'true',
* 'Group'=>$this->Group->save(array('id'=>null, 'name'=>'Debugger')) // **
WHAT DO I HAVE TO DO HERE TO ADD MULTIPLE RELATED GROUPS FOR THIS USER???*
)
);
$this->User->save();
}
--
Our newest site for the community: CakePHP Video Tutorials
http://tv.cakephp.org
Check out the new CakePHP Questions site http://ask.cakephp.org and help others
with their CakePHP related questions.
To unsubscribe from this group, send email to
[email protected] For more options, visit this group at
http://groups.google.com/group/cake-php