THIS CONTENT IS OUT OF DATE! IF YOU’RE USING CAKE 2, YOU SHOULDN’T READ THIS.
Wow, I haven’t posted anything on my blog for a while. I guess I must be busy. A new baby will have that effect.
Anyway, I’m happy to release an update to my Copyable behavior, which I shared with everyone a few months ago.
Along with some general bug fixes, this newest version has a couple of significant bug fixes:
- Validation is no longer performed before saving the new record. Validation was causing some issues with deep hasMany associations. I don’t see validation as necessary for copying anyway, since the original record already exists.
- For model associations that can be infinitely nested, such as Page hasMany ChildPage (and then that ChildPage hasMany ChildPage, etc.), copying stops after the first level of containment. These types of associations were causing infinite loops when generating the contain array.
There’s also a new setting, “ignore”, which allows you to specify, via dot (.) notation, contained models that should be ignored.
For example, if a contain array for your model looks like this:
$contain = array( 'Page' => array('Image'), 'Log', 'User' => array('Group' => array('Permission')) );
You can exclude the “Permission” contain by specifying the ignore setting:
public $actsAs = array('Copyable' => array('ignore' => array('User.Group.Permission')));
Handy for excluding certain assocations that don’t need to be copied, like changelogs and that sort of thing.
Enjoy, and, as always, comments and suggestions welcome!