The basic idea behind this behavior is that you (well, once in a while) need to save two HABTM models at the same time or search across both models, which are involved in the HABTM relationship.
There is a number of examples (some you can find even on this blog) on how to save a Post with a few Tags.Most of them, so far, had shown how to easily save Tags when the ID’s are already known.
Update: Since writing of this article the ‘rule’ => ‘multiple’ has been implemented in cake core.It is much more convenient to use for HABTM validation.You may consider this post deprecated and only to be used for historical purposes or if you are working with an older…
An interesting question came up on IRC today, which essentially boils down to:“How to save extra fields in the join table for HABTM models, while creating a new record for one of the involved models all at once?”
Update (10/7/2009)… this functionality has been rolled into Habtamable behavior
An interesting question came up on IRC today…If I have Post HABTM Tag, how do I select only Posts that have Tags “new” AND “cakephp”?
If you haven’t read part 1, where I cover some HABTM basics, you should probably take a look at that article as well.
Part 2. Saving data
Part 1. The basics
HABTM seems to give a lot of people trouble, so I wanted to cover a few points that may or may not be in the manual. And I will assume here that you have basic understanding or some knowledge of HABTM…