HABTM selection seemingly ignores joinTable
- by TheCapn
I'm attempting to do a HABTM relationship between a Users table and Groups table. The problem is, that I when I issue this call:
$this->User->Group->find('list');
The query that is issued is:
SELECT [Group].[id] AS [Group__id], [Group].[name] AS [Group__name] FROM [groups] AS [Group] WHERE 1 = 1
I can only assume at this point that I have defined my relationship wrong as I would expect behavior to use the groups_users table that is defined on the database as per convention. My relationships:
class User extends AppModel {
        var $name = 'User';
        //...snip...
    var $hasAndBelongsToMany = array(
        'Group' => array(
            'className'             => 'Group',
            'foreignKey'            => 'user_id',
            'associationForeignKey' => 'group_id',
            'joinTable'             => 'groups_users',
            'unique'                => true,
        )
    );
        //...snip...
}
class Group extends AppModel {
    var $name = 'Group';
    var $hasAndBelongsToMany = array ( 'User' => array(
        'className'             => 'User',
        'foreignKey'            => 'group_id',
        'associationForeignKey' => 'user_id',
        'joinTable'             => 'groups_users',
        'unique'                => true,
    ));
}
Is my understanding of HABTM wrong? How would I implement this Many to Many relationship where I can use CakePHP to query the groups_users table such that a list of groups the currently authenticated user is associated with is returned?