Saturday, June 29, 2013

Re: Model::AfterFind $results format, associations

After running more tests, here's another confusor:

NullParent hasMany NullChild

$this->NullParent->saveAssociated([
           'NullParent' => ['name' => 'wee'],
           'NullChild' => [
               ['name' => 'wee'],
               ['name' => 'doo']
     ]
]);

debug($results) from beforeSave yields:

array(
'NullParent' => array(
'name' => 'wee'
),
'NullChild' => array(
(int) 0 => array(
'NullChild' => array(
'name' => 'wee'
)
),
(int) 1 => array(
'NullChild' => array(
'name' => 'doo'
)
)
)
)

Why is it AssocModel.{n}.AssocModel.id format here? It's just a simple, non-deep, hasMany associated save.

I know I'm mixing beforeSave with afterFind now, but it's really confusing. I've been using cake for many years now and I feel really frustrated not being able to grasp these conventions regarding Models=>callbacks=>array formats. It makes writing fat models a real pain.

--
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP
 
---
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cake-php+unsubscribe@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

No comments: