I've been reading the manual and have been trying to get some user
authentication going.  I have "Users", and they can belong to one
"Group".  Then a "Group" can have many "Users".

This is a summary of my DB tables and fields:

users
-------
id | email | password | group_id | created | modified

groups
---------
id | name | created | modified


My problem is when I do a findAll() on the User model, it will least
each user like it should, but it pairs the Group up with the same "id",
and not "group_id".  In other words, user with "id" of 2 will have
group with an "id" of 2, totally ignoring what the "group_id" defines
for that user.

When I reverse the search, and findAll() by Group, it will list the
groups, but return zero user's associated with the groups.


This is the model code I currently have.  I've tried multiple
variations of the foreignKey, dot syntax, just have "id", switching
between 'user_id' and 'group_id' in both models, and so on.

User.php
------------
class User extends AppModel
{
    // Its always good practice to include this variable.
    var $name = 'User';
    var $hasOne = array('Group' =>
                        array('className'    => 'Group',
                              'conditions'   => '',
                              'order'        => '',
                              'dependent'    =>  false,
                              'foreignKey'   => 'user_id'
                        )
                  );

}

Group.php
--------------
class Group extends AppModel
{
    // Its always good practice to include this variable.
    var $name = 'Group';
    var $hasMany = array('User' =>
                         array('className'   => 'User',
                               'limit'       => '5',
                               'foreignKey'  => 'group_id',
                               'dependent'   => false,
                               'exclusive'   => false,
                               'finderSql'   => ''
                         )
                  );

}


--~--~---------~--~----~------------~-------~--~----~
 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