Consider the following HABTM relationship in CakePHP 2.2.3:
class User extends AppModel { public $hasAndBelongsToMany = array( 'Role' => array( 'className' => 'Role', 'joinTable' => 'roles_users', 'foreignKey' => 'user_id', 'associationForeignKey' => 'role_id', ) ); }
This works fine, but when using an alias of type VeryUniqueAlias instead of Role and, accordingly, changing the UserController, the m: n relation is not stored in the database (the data passed to save() in the controller is equivalent).
This does not work:
class User extends AppModel { public $hasAndBelongsToMany = array( 'VeryUniqueAlias' => array( 'className' => 'Role', 'joinTable' => 'roles_users', 'foreignKey' => 'user_id', 'associationForeignKey' => 'role_id', ) ); }
This is inconvenient as CakePHP docs states that it should work. Any idea why it doesn't work for me? Did I miss something?
source share