Hi all, I'm running into a bit of trouble.

I'm getting this SQL error when I try to run a find for all users in the table.

Warning (512): SQL Error: 1066: Not unique table/alias: 'GameRoleUser'
[CORE/cake/libs/model/datasources/dbo_source.php, line 512]

Code | Context

$sql    =       "SELECT `GameRoleUser`.`id`, `GameRoleUser`.`game_id`,
`GameRoleUser`.`role_id`, `GameRoleUser`.`user_id`,
`GameRoleUser`.`id`, `GameRoleUser`.`game_id`,
`GameRoleUser`.`role_id`, `GameRoleUser`.`user_id` FROM
`ehjgame_role_users` AS `GameRoleUser` JOIN `ehjgame_role_users` AS
`GameRoleUser` ON (`GameRoleUser`.`user_id` IN (1, 2, 3, 4, 5, 6, 7,
10, 9, 11, 12, 15, 16, 17, 18, 21, 20, 22, 23, 24) AND
`GameRoleUser`.`game_role_user_id` = `GameRoleUser`.`id`)  WHERE 1 = 1
  "
$error  =       "1066: Not unique table/alias: 'GameRoleUser'"
$out    =       null

            $out = null;
            if ($error) {
                trigger_error("<span style =
\"color:Red;text-align:left\"><b>SQL Error:</b>
{$this->error}</span>", E_USER_WARNING);

DboSource::showQuery() -
CORE/cake/libs/model/datasources/dbo_source.php, line 512
DboSource::execute() - CORE/cake/libs/model/datasources/dbo_source.php, line 202
DboSource::fetchAll() -
CORE/cake/libs/model/datasources/dbo_source.php, line 338
DboSource::queryAssociation() -
CORE/cake/libs/model/datasources/dbo_source.php, line 788
DboSource::read() - CORE/cake/libs/model/datasources/dbo_source.php, line 653
Model::find() - CORE/cake/libs/model/model.php, line 1795
Controller::paginate() - CORE/cake/libs/controller/controller.php, line 997
UsersController::index() - APP/controllers/users_controller.php, line 34
Object::dispatchMethod() - CORE/cake/libs/object.php, line 114
Dispatcher::_invoke() - CORE/cake/dispatcher.php, line 256
Dispatcher::dispatch() - CORE/cake/dispatcher.php, line 230
[main] - APP/index.php, line 90

Query: SELECT `GameRoleUser`.`id`, `GameRoleUser`.`game_id`,
`GameRoleUser`.`role_id`, `GameRoleUser`.`user_id`,
`GameRoleUser`.`id`, `GameRoleUser`.`game_id`,
`GameRoleUser`.`role_id`, `GameRoleUser`.`user_id` FROM
`ehjgame_role_users` AS `GameRoleUser` JOIN `ehjgame_role_users` AS
`GameRoleUser` ON (`GameRoleUser`.`user_id` IN (1, 2, 3, 4, 5, 6, 7,
10, 9, 11, 12, 15, 16, 17, 18, 21, 20, 22, 23, 24) AND
`GameRoleUser`.`game_role_user_id` = `GameRoleUser`.`id`) WHERE 1 = 1


I have the following HABTM association defined in my User model

var $hasAndBelongsToMany = array( 'GameRoleUser' => array('with' =>
'GameRoleUser'));

and the GameRoleUser model has this

var $belongsTo = array(
                        'Game' => array('className' => 'Game',
                                                                'foreignKey' => 
'game_id',
                                                                'conditions' => 
'',
                                                                'fields' => '',
                                                                'order' => ''
                        ),
                        'Role' => array('className' => 'Role',
                                                                'foreignKey' => 
'role_id',
                                                                'conditions' => 
'',
                                                                'fields' => '',
                                                                'order' => ''
                        ),
                        'User' => array('className' => 'User',
                                                                'foreignKey' => 
'user_id',
                                                                'conditions' => 
'',
                                                                'fields' => '',
                                                                'order' => ''
                        )
        );


I have no idea why it's trying to join the GameRoleUser model twice. I
tried a few different variations and all end up in similar errors.
It's starting to look like I'm going to have to write custom queries.
Kind of disappointing since this is one of the main drawing points to
the framework.

On Fri, Sep 5, 2008 at 8:34 AM, Adrian Cardenas <[EMAIL PROTECTED]> wrote:
> Thanks guys, the articles did help and I think I have a starting point now.
>
> On Thu, Sep 4, 2008 at 11:01 PM, teknoid <[EMAIL PROTECTED]> wrote:
>>
>> Yes, you'd need a join table for your HABTM with id, user_id, game_id
>> *and* role_id
>>
>> I briefly explain how cake deals with the join table/model here:
>> http://teknoid.wordpress.com/2008/07/03/notes-on-cakephp-habtm-part-1-the-basics/
>>
>> In addition to Mariano's post, it should be good to get you going.
>>
>> On Sep 4, 10:38 pm, Adrian <[EMAIL PROTECTED]> wrote:
>>> I have 3 models
>>>
>>> User
>>> Role
>>> Game
>>>
>>> A User can belong to one or more Games.
>>> A Game has one or more Users.
>>> A User has a Role within each Game.
>>>
>>> It's that third association that's escaping me. I think the simplest
>>> way would be to create a 1:1:1 from User:Role:Game and then and a
>>> HABTM from User to Game. Am I off here?
>>>
>>> This is all in preparation to set up an ACL. Where,  depending on a
>>> User's Role within a Game, the User can edit, or not,  records
>>> belonging to that particular game. In other words if User A has GM
>>> Role in Game X, then the A can edit records relating to X. However A
>>> only has Player Role in Game Y and can view but not edit records
>>> relating to Y.
>>>
>>> Is my original way of thinking about this correct or is there a better
>>> way to accomplish this through Cake?
>> >>
>>
>
>
>
> --
> Adrian R. Cardenas
>



-- 
Adrian R. Cardenas

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"CakePHP" 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