Hi Joshua,

If you have a $data array containing data for a record in A and 0 or
more records in B, you can use saveAll.

So, if your $data is something like:

array(
  [A] => array(
    [id] => 12,
    [otherdata] => 'some string'
    ),

 [B] => array(
    [0] => array(..),
    [1] => array(..)
 )
);

you can call model A in your a-controller:

A->saveAll($data,array('atomic' => true, 'validate' => 'first'));

This will save all the data in the A-record and associated B-records.
But take care:

- This will only work if you have set up the relationship. So in A
there must be something like:
 var $hasMany = array('B' => array('dependent' => true))
  and in B:
 var $belongsTo = 'A'

  Check the meaning of these options here:
http://book.cakephp.org/view/78/Associations-Linking-Models-Together

- The 'atomic' option only works if you can use transactions, like in
mysql InnoDB (not the default myIsam) tables.

- Tip: put this before the line where you want to use saveAll, to see
if the $data is ok:
     pr($data); exit();


This will save A + B. The only thing it will not do is remove the
records in B that no longer belong to A. This is something I will post
an item about, right now.

Jelmer

--~--~---------~--~----~------------~-------~--~----~
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 
cake-php+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to