Friday, January 30, 2009

Model::saveAll() fails with validate = first and belongsTo associations

Hello,

I recently updated from RC2 to 1.2.1.8004 and I've got problems when
doing a saveAll with two new datasets.

Example:
1. Model Profile belongsTo User
2. ProfileController::add() => $this->Profile->saveAll($this->data,
array('validate' => 'first'))

The Controller::data is something like:
array(
'Profile' => array(
'salutation_id' => 'xx'
),
'User' => array(
'username' => 'papagurana',
'password' => 'xxxxx'
)
);

In the Model::saveAll method in line 1516 the belongsTo association
will be removed after the first loop iteration. That could not be
correct, because line 1514 ($this->__save(...)) will not save the
belongsTo association but only validates the belongsTo model (The user
model in this case).

This problem can be easily fixed with:
if($options['validate'] != 'first') {
unset($data[$association]);
}

This problem only occurs if both datasets are new and must be inserted
in the database and the foreign key is not already set.

Greetings and sorry for my english

papagurana

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

No comments: