'Has and Belongs to many' is where the objects are loosely tied together. If you used the stores
and managers
analogy, one store has many managers, and one manager has many stores (not sure how that works, maybe they are roving managers? :P).
Firstly I think the example you use with managers stores isn't HABTM. It's just one store
has many managers
, not many stores
. Using HABTM here would imply that managers can belong to multiple stores at the same time! However I will explain anyway.
Anyhow, when using HABTM, this relationship requires an intermediate table probably called manager_stores
or something similar. This would be set up automatically by CakePHP if using the automated tools. This lets you link an unlimited number of managers to an unlimited number of stores.
What happens when you update and delete records depends on the configuration of your MySQL Relationships (you need to use the InnoDB engine).
This is regardless of what relationship type you are using.
If you are using phpMyAdmin, go into the structure view of your table. Then click 'relation view'.
If you are set up with InnoDB correctly you should see the relations and two columns saying "ON UPDATE
" and "ON DELETE
". This determines the behavior when you modify records.
I would be here all day explaining the different types of ON DELETE and ON UPDATE actions. Try doing some research into relational database queries!
I hope this helps you a bit. I will happily answer any questions you have!