You have your keys reversed.
'foreignKey' => 'user_id',
'associationForeignKey' => 'group_id',
This same thing has caught me up, over and over again, due to looking
at the array and its keys from the wrong perspective. Rather than the
keys & values be about Group they are more about User, as pertains to
Group. I hope that makes sense. Just remember that the key with
'association' is for the 'other' model (ie. not the model for the
present class but the one that is the key in the $hasAndBelongsToMany
array.
A surprising number of examples out there have it reversed. I think
there's an example in the docs somewhere that has it reversed, also.
On Sat, Feb 23, 2008 at 10:22 AM, villas <[EMAIL PROTECTED]> wrote:
>
> Cake 1.2 Beta / Php 5.xx / Firebird 2
>
> I have never succeeded in making even the simplest HABTM association
> work. I tried scaffold and reading everything I could and
> experimenting different ways. Here is the simple setup:
>
> Users: id, name
> Groups: id, name
> Groups_Users: user_id, group_id
>
> Model: User.php
> class User extends AppModel {
>
> var $name = 'User';
> var $useTable = 'users';
>
> var $hasAndBelongsToMany = array(
> 'Group' => array('className' => 'Group',
> 'joinTable' => 'groups_users',
> 'foreignKey' => 'group_id',
> 'associationForeignKey' => 'user_id',
> 'unique' => true,
> 'conditions' => '',
> 'fields' => '',
> 'order' => '',
> 'limit' => '',
> 'offset' => '',
> 'finderQuery' => '',
> 'deleteQuery' => '',
> 'insertQuery' => ''
> )
> );
> }
>
> When I use 'find' in my user controller and then dump the array, I
> get the [user] array data, but [group] array is always empty.
>
> The debug message shows the SQL from two queries. When I run the
> queries manually they each return data (from users and groups
> respectively) as expected.
>
> I know it should be simple, but why can't I get the [group] array
> populated from the queries. It has been driving me mad!
>
> Regards, villas
> >
>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Cake
PHP" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---