I am writing an installer, and as such I need to save multiple types of data in different tables, even when not associated. Ideally I woud like to take care of this all at once. Here is a brief of what I have so far.
Here is my cake array in preparation for saving said data.
$initialData = array(
array( 'Option' => array( 'name' => 'version', 'value' => '1.0.0', )),
array( 'Option' => array( 'name' => 'non-version', 'value' => '1.0.2', )),
array( 'User' => array( 'username' => 'skyler', 'password' => 'hi', )),
);
And I use the following to try and save it.
$this->Option->saveMany($initialData)
Which only saves the Option rows, not the User rows. Thoughts?
NOTE: This is NOT associated data. Options and Users are not associated, but need to be saved at the same time.
The
$this->Option->saveManywill work because you are saving multiple records for a single table. However, because the User is not associated to the Option, it does not know what to do with the data. You will need to call$this->User->save($initialData).If you expect to have multiple user records, you can call
$this->User->saveMany($initialData).Be sure not to forget to call
$this->User->create().