I have the following situation:
cake 1.3 / php5 / mysql 5
Companies** table **1:m ->** **Company_addresses** table **and Users
table.
Users** table has **1:m ->**** User_telephonenumbers table
I want to save from one form using multiple CompanyAddresses and
multiple UserTelephonenumbers. (code for form at bottom)
To put this in a graphic structure:
Companies table
1:m -> Company_addresses table (
1:m -> Users table
* * 1:m -> User_telephonenumbers table
My question is how can I tackle this problem elegantly?
-I tried saveAll but it does not save the telephone numbers..
-I tried transactions in combination with save per model method but it
seems like the transactions do not work (I see them in my sql dump but
it saves the addresses.
-I tried hybrid af these two but saveAll seems to also use
transactions.
Maybe I should validate up front?
Anyway does anybody have a solution?
code form:
<?php echo $this->Form->create('Register');?>
<fieldset>
<legend><?= __('Registreer uw bedrijf'); ?></legend>
<?php
echo $this->Form->input('Company.subscription_type',
array('options' => Configure::read('Company.subscription_type')));
echo $this->Form->input('Company.kvk', array('label'=>__('Uw
kvk nummer')));
echo $this->Form->input('Company.name',
array('label'=>__('Bedrijfsnaam')));
echo $this->Form->input('CompanyAddress.0.street',
array('label'=>__('straat en huisnr')));
echo $this->Form->input('CompanyAddress.0.zipcode',
array('label'=>__('postcode')));
echo $this->Form->input('CompanyAddress.0.city',
array('label'=>__('stad')));
?>
</fieldset>
<fieldset>
<legend><?= __('Contact informatie'); ?></legend>
<?php
echo $this->Form-
>input('User.first_name',array('label'=>__('voornaam')));
echo $this->Form-
>input('User.last_name',array('label'=>__('achternaam')));
echo $this->Form->input('UserTelnr.0.tel',
array('label'=>__('telefoon')));
echo $this->Form->input('UserTelnr.1.tel',
array('label'=>__('mobiel')));
echo $this->Form->input('UserTelnr.2.tel',
array('label'=>__('fax')));
?>
</fieldset>
<fieldset>
<legend><?= __('factuur adres'); ?></legend>
<?php
echo $this->Form->input('CompanyAddress.
1.tav',array('label'=>__('ter attentie van/afdeling')));
echo $this->Form->input('CompanyAddress.
1.street',array('label'=>__('straat en huisnr')));
echo $this->Form->input('CompanyAddress.
1.zipcode',array('label'=>__('postcode')));
echo $this->Form->input('CompanyAddress.
1.postbox',array('label'=>__('postbus')));
echo $this->Form->input('CompanyAddress.1.city',
array('label'=>__('plaats')));
?>
</fieldset>
<fieldset>
<legend><?= __('Geef uw login gegevens'); ?></legend>
<?php
echo $this->Form-
>input('User.username',array('label'=>__('gebruikersnaam/email')));
echo $this->Form-
>input('User.password',array('label'=>__('wachtwoord')));
echo $this->Form-
>input('User.password2',array('label'=>__('herhaal wachtwoord')));
?>
</fieldset>
<?php echo $this->Form->end(__('Submit', true));?>
</div>
code company model
var $hasMany = array(
'CompanyAddress' => array(
'className' => 'CompanyAddress',
'foreignKey' => 'company_id',
'dependent' => false,
'conditions' => '',
'fields' => '',
'order' => '',
'limit' => '',
'offset' => '',
'exclusive' => '',
'finderQuery' => '',
'counterQuery' => ''
),
'User' => array(
'className' => 'User',
'foreignKey' => 'company_id',
'dependent' => false,
'conditions' => '',
'fields' => '',
'order' => '',
'limit' => '',
'offset' => '',
'exclusive' => '',
'finderQuery' => '',
'counterQuery' => ''
)
=== code user model ===
var $belongsTo = array(
'Group' => array(
'className' => 'Group',
'foreignKey' => 'group_id',
'conditions' => '',
'fields' => '',
'order' => ''
),
'Company' => array(
'className' => 'Company',
'foreignKey' => 'company_id',
'conditions' => '',
'fields' => '',
'order' => ''
)
);
var $hasMany = array(
'UserTelnr' => array(
'className' => 'UserTelnr',
'foreignKey' => 'user_id',
'dependent' => false,
'conditions' => '',
'fields' => '',
'order' => '',
'limit' => '',
'offset' => '',
'exclusive' => '',
'finderQuery' => '',
'counterQuery' => ''
),
--
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
[email protected] For more options, visit this group at
http://groups.google.com/group/cake-php