Friday, December 9, 2011

Re: Update field in associated model???

Its creates a new record since the primary key Setting.id is not specified..

you could :

$this->User->Setting->updateAll(
array('Setting.prefered_language' => $lang),
array('Setting.user_id => $user_id)
);


Andras Kende
http://www.kende.com

On Dec 9, 2011, at 5:53 AM, flosky wrote:

> Hi everyone.
>
> I'm having trouble with what should be an easy task.
> First up I'm using Cake 2.0.2.
> I have a User and Setting table with User hasOne Setting association.
> Now I want to update fields of the Setting table, 'prefered_language'
> for example.
> This does either not work at all, or creates a new row and doesnt
> update.
> What I would expect to work is the following:
> $data = array('Setting' => array('user_id' => $user_id,
> 'prefered_language' => $lang));
> $this->save($data);
> But this creates a new row!!
> I can of course (but i dont want to) read the id first and include
> that into the $data array.
>
> I have also tried saveAssociated via the User model (which doesnt work
> at all).
>
> Since that should be a common task, how have some of you guys
> implemented this??
>
> Thanks
> -flosky
>
> --
> 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

--
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

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate