1
votes

In my Cakephp application I have define HABTM relation between User Table ( /app/Model/User.php) and Group Table (/app/Model/Group.php ) on 'username'(of User Table) and 'group_id'(of Group Table).

And the relation table is user_groups ( /app/Model/UserGroup.php).

In my application I want to add one raw in UserGroup containing group_id="something" and username=NULL.

As per HABTM defination it's not allow to add raw contain null 'username'. But in CakePHP Documentation there is option for custom insertQuery.

SO how to write this custom insertQuery for some special condition ?

1

1 Answers

0
votes

In cakephp you cannote modify the table of join of an HABTM relationship. If you want a custom join table you have to create manually inside the database it, create its model and in UeserModel use an hasMany relation with UserGroup and the same thing inside the table Group.

This is how to customize a join table in a HABTM relationship in cakephp.