I have the following association:
Group hasAndBelongsToMany User, with the groups_users join table.
When I create a new group, I want to add to the join table the founder of the group.
My $this->data array looks like:
Array
(
[Group] => Array
(
[name] => seyufgsduifsj
[access] => 2
[founder_id] => 3
[random_key] => I6XC7uMTelpTSdq8DbtLPjqubiF7s6Pn
)
[GroupsUser] => Array
(
[user_id] => 3
[group_role_id] => 1
[random_key] => PZsDZXcoCTHw1IuvqsfURVpPX6AcZ3r2
)
)
I tried with save() and saveAll(), but it would add only the group in the groups table and not the user-group association.
So, basically, I have an add form where the user fills in the group name and access. Then, if the data validates, I add a couple of more field values to the group array (like random_key) and to the join table array (like user_id and group_role_id). I want Cake to save the group first, take its id, update the join table array with the proper group_id, and then save this second array too.
Is this possible in a straight-forward way, or do I have to write two consequent save() methods, for the second one providing the last inserted id in the first one?
Thanks!