How To Save Associated HABTM Models in CakePHP

A common problem programmers have with CakePHP is saving related models with a many-to-many relationship, something Cake calls “hasAndBelongsToMany” or HABTM. One of the things that makes saving HABTM models so challenging is that when you go to save your models, Cake will act like everything saved fine when in fact only one of the models saved, or in some cases, none of them saved. To illustrate how to overcome this common problem, let’s say you’ve just read Dr.