I’m working with CakePHP 2.x and I was wondering if there is any built-in functionality for working with HABTM join tables. I don’t really see anything in the documentation for directly changing the attributes of a HABTM relationship. This is what I mean:
I have a join table that contains flags for a relationship between two models that can be demonstrated as such:
(int) id | (int) user_id | (int) video_id | (bool) hasRated | (bool) hasWatched | (bool) hasDownloaded
The first column is just the regular table id. The next two (user_id and video_id) are the typical HABTM foreign keys to the user table and video table. The following 3 flags are indicators of the relationship between the two models (has this video been watched? has it been rated? etc.)
I am currently building my own queries and this is my boot-strap setup. My end goal is to add attributes between the relationship of two models. Is this the correct way to approach this, or is there a more Cakey way to do it?
Eureka.
In 2.x, cake will automagically create a model for you and recognize the relationship.
$this->Video->UserVideowill generate a model that fits the HABTM join tableusers_videos. You can then interact with it just like a regular model and it will update the database.