Thursday, June 28, 2012

saveAssociated with hasOne creates new entries instead of updating

Hello,

saveAssociated keeps generating new entries, rather than updating old ones:

User hasOne UserProfile
User hasOne UserSetting

My Form looks like this:



<?php echo $this->Form->create('User', array('type'=>'post')); ?>
<?php echo $this->Form->input('User.id'); ?>

<?php echo $this->Form->input('UserProfile.firstname'); ?>
<?php echo $this->Form->input('UserProfile.name'); ?>

<?php echo $this->Form->input('UserSetting.some_setting'); ?>

<?php echo $this->Form->end('save'); ?>


The resulting array looks like this:

[User] => Array
    (
        [id] => 3
    )

[UserProfile] => Array
    (
        [firstname] => Test
        [name] => Name
    )

[UserSetting] => Array
    (
        [some_setting] => Doh
    )                    
    
    
In my controller I simply call

$this->User->saveAssociated($this->request->data);


As I understand the book, cakephp should populate the UserProfile.user_id and UserSetting.user_id field automatically. But the result is, with every save, a new association entry is generated. The User field updates correct.

What is my problem here? Any clues?

Regards,
cronet

--
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
cake-php+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php

No comments: