Sunday, October 31, 2010

Problem with a hasMany relationship

hi guys,

i'm trying to add data to a model wich have a $hasMany relationship but with no luck...

According to the cookbook, i must have in my model something like this

class User extends AppModel {

$hasMany = 'profile';

...

then in my view i use the form helper:

$this->Form->create('user');
$this->Form-Z>input('user.id);
$this->Form->input('user.username');
$this->Form->input('user.password');
$this->Form->input('profile.0.name');
$this->Form->input('profile.0.age');
...etc...

I want to save that user and that profile (in the future i want to add more profiles to one user)

so in my controler I'm doing the following:

if(!empty($this->data) {
  $this->User->saveAll($this->data);
}

...

well, the user is saved, but nothing happens with the profile... I have the models for both defined and in my database i have a foreign key in the profile table which point to user (i'm using mysql with innodb)

I'm missing something?

Hope you can help me,

Thanks in advance!

Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions.
 
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to
cake-php+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en

No comments: