I have following situation:
I'm developing an address-application to store the details of our clients.
I've got the following db-structure:
Clients hasMany Addresses
Addresses belongsTo Client
Addresses hasMany AddressEmails and AddressPhones
If someone now adds a new client, his primary address with 1 email and 1 phonenumber should be saved.
That works partly very good if I do this in the add-view of the client with the following code and call the saveAll-method in the client-controller:
<?php
echo $this->Form->input('client_group_id');
echo $this->Form->input('company');
echo $this->Form->input('firstname');
echo $this->Form->input('lastname');
echo $this->Form->input('www');
echo $this->Form->input('Address.0.is_standard', array('type' => 'hidden', 'value' => '1'));
echo $this->Form->input('Address.0.street');
echo $this->Form->input('Address.0.zip');
echo $this->Form->input('Address.0.city');
?>
But I have no idea how to save the email and the phone number over this view. Tried thinks like AddressEmail.0.email but that didn't work.
Got it:
With Nik's posted solution it's working fine, I'm now calling $this->Client->Address->saveAll($this->data) but had to adjust my add-view like this:
<?php
echo $this->Form->input('client_group_id');
echo $this->Form->input('company');
echo $this->Form->input('firstname');
echo $this->Form->input('lastname');
echo $this->Form->input('www');
echo $this->Form->input('Address.is_standard', array('type' => 'hidden', 'value' => '1'));
echo $this->Form->input('Address.street');
echo $this->Form->input('Address.zip');
echo $this->Form->input('Address.city');
echo $this->Form->input('AddressEmail.0.type', array('type' => 'hidden', 'value' => 'Standard'));
echo $this->Form->input('AddressEmail.0.email');
echo $this->Form->input('AddressPhone.0.type', array('type' => 'hidden', 'value' => 'Standard'));
echo $this->Form->input('AddressPhone.0.number');
?>
Since I'm now calling the saveAll()-method from the Address-Model the zeros are not needed anymore!