I have a table applications with a HABTM relationship with another table named users. The table linking these 2 together is applications_users.
Now, with this code,
$data = array(
'Application' => array(
'id' => 123
),
'User' => array(
'application_id' => 123,
'user_id' => 456
)
);
$this->Application->saveAll($data);
I’m getting the expected lines in my tables, but I’m also getting a strange line in applications_users that contains 123 in both applicaiton_id and user_id.
Any idea where this line does come form ? And how to avoid it ?
Cake magic put it there!
And it is supposed to as it is, as you said, the link table between applications and users tables.
The HABTM relationship is a “many-to-many” relationship that need a third table to link records from the two tables.
The key code here is this:
that tell cake that the user belongs to the application with the id=123 and also that the user with the id=123 has the application with id (application_id)=123.
If you don’t want to link the two, remove the above line.