I see, so we also needed to provide the id of 'children' (TelephonyNumber)
that belongs to the 'parent' (Person). but i have a different problem, in my
case, i also can adding some ShiftDetail (child), on the page, but not to
create a new Shift (parent) just adding the ShiftDetail to the exist Shift.
but i now get the understanding, when i don't provide the id for ShiftDetail
on the form, Cake will just create new Shift (parent) and correlate that
ShiftDetail with the new Shift, even i triggered on the exist Shift
(shifts/edit/1).
To my problem. i'm going to 'pragmatic' approach on the edit function on
controller
if ($this->Shift->save($this->data)) { // to update the Shift (parent)
//adding new ShiftDetail to the current Shift
$this->Shift->ShiftDetail->saveAll($this->data, array('validate' =>
'first'));
}
Thank's, now i know why saveAll didn't work before. but i still wonder if
the process can done in one function $this->Shift->saveAll, to update +
adding (if users add new).
On Thu, Sep 10, 2009 at 3:59 PM, WebbedIT <[email protected]> wrote:
>
> Here is one of my forms which updates a Person model and User
> (hasOne), TelephonyNumber (hasMany) and OnlineAddress (hasMany)
>
> Edit View:
>
> echo $form->create('Person');
> echo $form->input('Person.id');
> echo $form->input('Person.title_id');
> echo $form->input('Person.first_name');
> echo $form->input('Person.middle_name');
> echo $form->input('Person.last_name');
> echo $form->input('Person.gender_id');
> echo $this->element('date_jscalendar', array
> ('id'=>'PersonDateOfBirth', 'model'=>'Person',
> 'field'=>'date_of_birth', 'label'=>'Date of Birth'));
> echo $form->input('TelephonyNumber.0.id');
> echo $form->input('TelephonyNumber.0.parent_model', array
> ('type'=>'hidden', 'value'=>'Person'));
> echo $form->input('TelephonyNumber.0.type_id', array
> ('type'=>'hidden', 'value'=>51));
> echo $form->input('TelephonyNumber.0.number', array
> ('label'=>'Telephone'));
> echo $form->input('OnlineAddress.0.id');
> echo $form->input('OnlineAddress.0.parent_model', array
> ('type'=>'hidden', 'value'=>'Person'));
> echo $form->input('OnlineAddress.0.type_id', array('type'=>'hidden',
> 'value'=>54));
> echo $form->input('OnlineAddress.0.address', array
> ('label'=>'Email'));
> echo $form->input('User.id');
> echo $form->input('User.username');
> echo $form->input('User.password', array('value'=>'', 'label'=>'New
> Password'));
> echo $form->input('User.password_confirm', array('type'=>'password',
> 'label'=>'Confirm Password', 'value'=>''));
> echo $form->input('User.is_active', array('label'=>'Active',
> 'options' => array('1' => 'Yes', '0' => 'No')));
> echo $form->input('User.is_deleted', array('label'=>'Deleted',
> 'options' => array('0' => 'No', '1' => 'Yes')));
> echo $form->input('User.user_group_id');
> echo $form->end('Submit');
>
> Controller:
>
> if ($this->Person->saveAll($this->data, array('validate'=>'first'))) {
> $this->Session->setFlash('User updated');
> $this->redirect('view/'.$this->Person->id);
> } else {
> $this->Session->setFlash('User not updated, correct errors and
> resubmit');
> }
>
> Simple, just make sure you have the right ID values included in the
> form.
>
> P.S. The TelephonyNumber and OnlineAddress form fields are named
> differently due to their hasMany associations
> >
>
--
Mukhamad Ikhsan
+6281572181283
Y!id:ikhsan.only
http://www.diodachi.com
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"CakePHP" group.
To post to this group, send email to [email protected]
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
-~----------~----~----~----~------~----~------~--~---