Monday, July 7, 2014

Re: CakePHP 3.0.0-alpha1 save hasOne

For first level associations it is not necessary to add  ['associated' => ['ComputerConfigs'] a normal save() should work.

I suggest to take a look at your Computer entity file. It should list the field 'computer_config' in the $_accessible array. Otherwise the tampering protection mechanism will block the field and the value will be lost.

On Sunday, July 6, 2014 10:53:44 PM UTC+2, kalb...@gmail.com wrote:
Hi,

Now that cakephp 3 is in alpha, i'm trying to port an app written with cakephp 2.x.

Before the problem, i have to say that the team is doing an amazing job...the new orm, no more array[][][] headache and much more ^^

So i have two model which are: Computers and ComputerConfigs.
The association is Computer hasOne ComputerConfig and ComputerConfig belongsTo Computer.

In edit view i have one form for both model.

input example for computer field:
$this->Form->input('ip_address');

input example for computer_config field:
$this->Form->input('computer_config.harddrive');

In Cake 2.X, i call:
$this->Computer->saveAssociated($this->request->data);

All is updated correctly in 2.x, but in 3.0, if i understand the book/api, i must do:

$computer = $this->Computers->patchEntity($computer, $this->request->data, ['ComputerConfigs']);
$this->Computers->save($computer, ['associated' => ['ComputerConfigs']);

The change made to Computer fields are saved but not the change to ComputerConfigs.

If i debug $computer, i have 2 entities, one for both model, with updated values for properties.
If i do 2 patchEntity (one for Computer and one for ComputerConfigs), and saved thems: all is good.

I probably don't understand something, so any help is welcome.

Thanks.

Ps: sorry for my english.

--
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

---
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cake-php+unsubscribe@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/d/optout.

No comments: