Re: CakePHP 3.0.0-alpha1 save hasOne
Glad that it worked :) On Monday, July 7, 2014 2:38:42 PM UTC+2, kalb...@gmail.com wrote: > > Thank for your answer, and yes it works after checking the $_accessible > var. > I baked whole project, and by default the association was "hasMany" and > not hasOne. > I corrected this just after baking but not $_accessible who stay with > computer_config*s* instead of computer_config. > > Thank's again. > > Le lundi 7 juillet 2014 11:41:37 UTC+2, José Lorenzo a écrit : >> >> 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. >> >> -- 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+unsubscr...@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.
Re: CakePHP 3.0.0-alpha1 save hasOne
Thank for your answer, and yes it works after checking the $_accessible var. I baked whole project, and by default the association was "hasMany" and not hasOne. I corrected this just after baking but not $_accessible who stay with computer_config*s* instead of computer_config. Thank's again. Le lundi 7 juillet 2014 11:41:37 UTC+2, José Lorenzo a écrit : > > 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. > > -- 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+unsubscr...@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.
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+unsubscr...@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.
CakePHP 3.0.0-alpha1 save hasOne
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+unsubscr...@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.
Re: Save hasOne
Store the id in the session. On Oct 8, 9:25 am, Günther Theilen <[EMAIL PROTECTED]> wrote: > OK, I'll have another look at the security component. > The last time I tried it, I found the same you did: it caused more > problems than it solved. > > Thanks anyway. > > grigri: > > > If you use the Security Component then the Form Helper will > > automatically generate and manage hash fields to make sure that hidden > > fields are not modified (amongst other things) (I've found it to cause > > more problems than it solves, however - give it a go). > > > To be honest, I rarely make use of saveAll(), I generally override the > > save() function in the model to save the associated models I need to. > > This way I'm 100% in control of what happens and when. I'll probably > > get used to saveAll() eventually though... > > > On Oct 8, 1:40 pm, Günther Theilen <[EMAIL PROTECTED]> wrote: > >> Yeah, I thought about that. > >> But what happens if a user changes the value of the hidden field > >> AdvancedEntry.id? > >> So I would have to check if the field has the right value. And in that > >> case I could just drop the hidden field. > > >> Or am I missing something? > > >> Regards > >> Guenther > > >> grigri wrote: > >>> Add a hidden field containing the AdvancedEntry id to the form: > >>> echo $form->input('BasicEntry.bacon'); > >>> echo $form->input('AdvancedEntry.id'); > >>> echo $form->input('AdvancedEntry.eggs'); > >>> (The `id` of the BasicEntry is transmitted to the edit action as the > >>> 1st parameter, so you don't need to do this for the primary model. It > >>> doesn't hurt, though) > >>> (id fields are hidden by default, so you don't need to specify it) > >>> hth > >>> grigri > >>> On Oct 8, 9:45 am, Günther Theilen <[EMAIL PROTECTED]> wrote: > Hi, > let's say there are two models: > BasicEntry hasOne AdvancedEntry > AdvancedEntry belongsTo BasicEntry > In the advanced_entries table in the DB there is a field called > "basic_entry_id" > In views/basic_entries_edit.ctp there is something like this: > $form->input('BasicEntry.foo'); > $form->input('AdvancedEntry.bar'); > In the basic_entries_controller/edit method I have: > $this->BasicCity->save($this->data); > which saves only the data for the BasicEntry. > So I assumed I have to use saveAll() which doesn't work quite as I > expected. > If I don't set $this->data['AdvancedEntry']['id'] manually before > saveAll I get an INSERT instead of an UPDATE. > I set the value with something like this: > $this->data['AdvancedEntry']['id'] = > $this->BasicEntry->AdvancedEntry->field('id', array( > 'basic_entry_id' => $this->data['BasicEntry']['id'])); > Do I really have to do this manually or is there an automagic cake-like > way? > Regards > Guenther > > --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---
Re: Save hasOne
OK, I'll have another look at the security component. The last time I tried it, I found the same you did: it caused more problems than it solved. Thanks anyway. grigri: > If you use the Security Component then the Form Helper will > automatically generate and manage hash fields to make sure that hidden > fields are not modified (amongst other things) (I've found it to cause > more problems than it solves, however - give it a go). > > To be honest, I rarely make use of saveAll(), I generally override the > save() function in the model to save the associated models I need to. > This way I'm 100% in control of what happens and when. I'll probably > get used to saveAll() eventually though... > > On Oct 8, 1:40 pm, Günther Theilen <[EMAIL PROTECTED]> wrote: >> Yeah, I thought about that. >> But what happens if a user changes the value of the hidden field >> AdvancedEntry.id? >> So I would have to check if the field has the right value. And in that >> case I could just drop the hidden field. >> >> Or am I missing something? >> >> Regards >> Guenther >> >> grigri wrote: >>> Add a hidden field containing the AdvancedEntry id to the form: >>> echo $form->input('BasicEntry.bacon'); >>> echo $form->input('AdvancedEntry.id'); >>> echo $form->input('AdvancedEntry.eggs'); >>> (The `id` of the BasicEntry is transmitted to the edit action as the >>> 1st parameter, so you don't need to do this for the primary model. It >>> doesn't hurt, though) >>> (id fields are hidden by default, so you don't need to specify it) >>> hth >>> grigri >>> On Oct 8, 9:45 am, Günther Theilen <[EMAIL PROTECTED]> wrote: Hi, let's say there are two models: BasicEntry hasOne AdvancedEntry AdvancedEntry belongsTo BasicEntry In the advanced_entries table in the DB there is a field called "basic_entry_id" In views/basic_entries_edit.ctp there is something like this: $form->input('BasicEntry.foo'); $form->input('AdvancedEntry.bar'); In the basic_entries_controller/edit method I have: $this->BasicCity->save($this->data); which saves only the data for the BasicEntry. So I assumed I have to use saveAll() which doesn't work quite as I expected. If I don't set $this->data['AdvancedEntry']['id'] manually before saveAll I get an INSERT instead of an UPDATE. I set the value with something like this: $this->data['AdvancedEntry']['id'] = $this->BasicEntry->AdvancedEntry->field('id', array( 'basic_entry_id' => $this->data['BasicEntry']['id'])); Do I really have to do this manually or is there an automagic cake-like way? Regards Guenther > > --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---
Re: Save hasOne
If you use the Security Component then the Form Helper will automatically generate and manage hash fields to make sure that hidden fields are not modified (amongst other things) (I've found it to cause more problems than it solves, however - give it a go). To be honest, I rarely make use of saveAll(), I generally override the save() function in the model to save the associated models I need to. This way I'm 100% in control of what happens and when. I'll probably get used to saveAll() eventually though... On Oct 8, 1:40 pm, Günther Theilen <[EMAIL PROTECTED]> wrote: > Yeah, I thought about that. > But what happens if a user changes the value of the hidden field > AdvancedEntry.id? > So I would have to check if the field has the right value. And in that > case I could just drop the hidden field. > > Or am I missing something? > > Regards > Guenther > > grigri wrote: > > Add a hidden field containing the AdvancedEntry id to the form: > > > echo $form->input('BasicEntry.bacon'); > > echo $form->input('AdvancedEntry.id'); > > echo $form->input('AdvancedEntry.eggs'); > > > (The `id` of the BasicEntry is transmitted to the edit action as the > > 1st parameter, so you don't need to do this for the primary model. It > > doesn't hurt, though) > > > (id fields are hidden by default, so you don't need to specify it) > > > hth > > grigri > > > On Oct 8, 9:45 am, Günther Theilen <[EMAIL PROTECTED]> wrote: > >> Hi, > > >> let's say there are two models: > > >> BasicEntry hasOne AdvancedEntry > >> AdvancedEntry belongsTo BasicEntry > > >> In the advanced_entries table in the DB there is a field called > >> "basic_entry_id" > > >> In views/basic_entries_edit.ctp there is something like this: > > >> $form->input('BasicEntry.foo'); > >> $form->input('AdvancedEntry.bar'); > > >> In the basic_entries_controller/edit method I have: > > >> $this->BasicCity->save($this->data); > > >> which saves only the data for the BasicEntry. > >> So I assumed I have to use saveAll() which doesn't work quite as I > >> expected. > > >> If I don't set $this->data['AdvancedEntry']['id'] manually before > >> saveAll I get an INSERT instead of an UPDATE. > >> I set the value with something like this: > > >> $this->data['AdvancedEntry']['id'] = > >> $this->BasicEntry->AdvancedEntry->field('id', array( > >> 'basic_entry_id' => $this->data['BasicEntry']['id'])); > > >> Do I really have to do this manually or is there an automagic cake-like > >> way? > > >> Regards > >> Guenther --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---
Re: Save hasOne
Yeah, I thought about that. But what happens if a user changes the value of the hidden field AdvancedEntry.id? So I would have to check if the field has the right value. And in that case I could just drop the hidden field. Or am I missing something? Regards Guenther grigri wrote: > Add a hidden field containing the AdvancedEntry id to the form: > > echo $form->input('BasicEntry.bacon'); > echo $form->input('AdvancedEntry.id'); > echo $form->input('AdvancedEntry.eggs'); > > (The `id` of the BasicEntry is transmitted to the edit action as the > 1st parameter, so you don't need to do this for the primary model. It > doesn't hurt, though) > > (id fields are hidden by default, so you don't need to specify it) > > hth > grigri > > On Oct 8, 9:45 am, Günther Theilen <[EMAIL PROTECTED]> wrote: >> Hi, >> >> let's say there are two models: >> >> BasicEntry hasOne AdvancedEntry >> AdvancedEntry belongsTo BasicEntry >> >> In the advanced_entries table in the DB there is a field called >> "basic_entry_id" >> >> In views/basic_entries_edit.ctp there is something like this: >> >> $form->input('BasicEntry.foo'); >> $form->input('AdvancedEntry.bar'); >> >> In the basic_entries_controller/edit method I have: >> >> $this->BasicCity->save($this->data); >> >> which saves only the data for the BasicEntry. >> So I assumed I have to use saveAll() which doesn't work quite as I expected. >> >> If I don't set $this->data['AdvancedEntry']['id'] manually before >> saveAll I get an INSERT instead of an UPDATE. >> I set the value with something like this: >> >> $this->data['AdvancedEntry']['id'] = >>$this->BasicEntry->AdvancedEntry->field('id', array( >> 'basic_entry_id' => $this->data['BasicEntry']['id'])); >> >> Do I really have to do this manually or is there an automagic cake-like way? >> >> Regards >> Guenther > > --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---
Re: Save hasOne
Add a hidden field containing the AdvancedEntry id to the form: echo $form->input('BasicEntry.bacon'); echo $form->input('AdvancedEntry.id'); echo $form->input('AdvancedEntry.eggs'); (The `id` of the BasicEntry is transmitted to the edit action as the 1st parameter, so you don't need to do this for the primary model. It doesn't hurt, though) (id fields are hidden by default, so you don't need to specify it) hth grigri On Oct 8, 9:45 am, Günther Theilen <[EMAIL PROTECTED]> wrote: > Hi, > > let's say there are two models: > > BasicEntry hasOne AdvancedEntry > AdvancedEntry belongsTo BasicEntry > > In the advanced_entries table in the DB there is a field called > "basic_entry_id" > > In views/basic_entries_edit.ctp there is something like this: > > $form->input('BasicEntry.foo'); > $form->input('AdvancedEntry.bar'); > > In the basic_entries_controller/edit method I have: > > $this->BasicCity->save($this->data); > > which saves only the data for the BasicEntry. > So I assumed I have to use saveAll() which doesn't work quite as I expected. > > If I don't set $this->data['AdvancedEntry']['id'] manually before > saveAll I get an INSERT instead of an UPDATE. > I set the value with something like this: > > $this->data['AdvancedEntry']['id'] = > $this->BasicEntry->AdvancedEntry->field('id', array( > 'basic_entry_id' => $this->data['BasicEntry']['id'])); > > Do I really have to do this manually or is there an automagic cake-like way? > > Regards > Guenther --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---
Save hasOne
Hi, let's say there are two models: BasicEntry hasOne AdvancedEntry AdvancedEntry belongsTo BasicEntry In the advanced_entries table in the DB there is a field called "basic_entry_id" In views/basic_entries_edit.ctp there is something like this: $form->input('BasicEntry.foo'); $form->input('AdvancedEntry.bar'); In the basic_entries_controller/edit method I have: $this->BasicCity->save($this->data); which saves only the data for the BasicEntry. So I assumed I have to use saveAll() which doesn't work quite as I expected. If I don't set $this->data['AdvancedEntry']['id'] manually before saveAll I get an INSERT instead of an UPDATE. I set the value with something like this: $this->data['AdvancedEntry']['id'] = $this->BasicEntry->AdvancedEntry->field('id', array( 'basic_entry_id' => $this->data['BasicEntry']['id'])); Do I really have to do this manually or is there an automagic cake-like way? Regards Guenther --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---