@blogica.  Thanks for your reply and although you may be right about
the keys being reversed in my inital post,  I had already tried them
both ways before posting.

You are also right about other examples being confused.  The CookBook
example seems to be wrong in a couple of ways and when I eventually
discover how this works,  I'll be delighted to propose amendments.

Until then,  perhaps the best way for me to figure this out is by
copying someone's working code.  Perhaps some kind soul would provide
the barest working example for me to copy.  Otherwise,  I hope blogica
or some other guru may provide an insight.


On Feb 23, 4:56 pm, "b logica" <[EMAIL PROTECTED]> wrote:
> 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
-~----------~----~----~----~------~----~------~--~---

Reply via email to