Hello,
I'm trying to create a simple behavior for data mapping - I have an
array with structure different than this in my model. Just an example:
$input=array('some_key'=>array('id'=>2,
'data'=>'some_data'),
'some_key2'=>array('data2'=>'some_data2'),
'data3'=>'some_data3')
but my model and respectively database table needs the data in format
like this:
$data=array('id'=>2,
'data'=>'some_data',
'data2'=>'some_data2',
'data3' =>'some_data3')
So, I wrote a simple behavior that can do this job in beforeValidate
callback - I pass the mapping relation between $input and $data in
behavior parameters, and remap it. Everything seemed to work fine, but
today I've sticked a weird problem: if the field "ID" (this it the
primary key for the model) is in nested array and is not present "at
first level" in $input, Cake tries to insert new record rather then
editing the existing one. This happens because in save method of
model, data is setted before callbacks execution, so when Cake sets
the model data it assumes that this is new record because ID is
missing (ID is set later in beforeValidate callback of my behavior).
I wonder what is the best way to solve this problem - I can create new
behavior method saveConverted() and to call it rather than $model-
>save, or may be just to do remapping in the behavior, return the
resulted data and to save it with $model->save().
Regards,
Nikolay
Check out the new CakePHP Questions site http://cakeqs.org and help others with
their CakePHP related questions.
You received this message because you are subscribed to the Google Groups
"CakePHP" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected] For more options, visit this group at
http://groups.google.com/group/cake-php?hl=en