Not quite sure what you're getting at, but please have a look:

class User extends AppModel {

        var $name = 'User';

        var $belongsTo = array(
                        'DefaultAccount' => array(
                                'className'             => 'Account',
                                'foreignKey'    => 'default_account_id'
                        )
        );

        var $hasMany = array(
                        'Account' => array(
                                'className'             => 'Account',
                                'foreignKey'    => 'user_id',
                                'dependent'             => true
                        )
        );

        var $hasAndBelongsToMany = array(
                        'Group' => array(
                                'className'             => 'Group',
                                'joinTable'             => 'groups_users',
                                'foreignKey'    => 'user_id',
                                'associationForeignKey' => 'group_id',
                                'unique'                => true
                        ),
                        'Friend' => array(
                                'className'             => 'User',
                                'joinTable'             => 'user_friends',
                                'foreignKey'    => 'user_id',
                                'associationForeignKey' => 'friend_id',
                                'unique'                => true
                        )
        );
}

On 7 May 2008, at 15:22, Grant Cox wrote:

>
> Can you post your $hasAndBelongsToMany variable definition?  I think
> you'll be able to fix your issue by just using the model alias
> prefixes in the 'foreignKey' and/or 'associationForeignKey' values.
>
>
> On May 7, 2:25 pm, David Christopher Zentgraf <[EMAIL PROTECTED]>
> wrote:
>> Hi,
>>
>> I'm stumbling across bug number 4194.https://trac.cakephp.org/ticket/4194
>>
>> I have a User model, which has a `name` field.
>> This User hasMany Accounts, which also have a `name` field.
>> The User also hasAndBelongsToMany other Users as a friend  
>> relationship.
>>
>> User (`name`, ...)
>> |
>> |- hasMany
>> |  |- Accounts (`name`, ...)
>> |
>> |- hasAndBelongsToMany
>>    |- User
>>
>> When I try to save such a User-User HABTM relationship, Cake is doing
>> all sorts of lookups, apparently for every linked model.
>> What it fails at is this query:
>>
>> SELECT COUNT(*) AS `count` FROM `users` AS `User`
>> LEFT JOIN `accounts` AS `DefaultAccount`
>>   ON (`User`.`default_account_id` = `DefaultAccount`.`id`)
>> WHERE ((`name` = '<username>')) AND `User`.`id` != 1
>>
>> 1052: Column 'name' in where clause is ambiguous
>>
>> The WHERE clause would need to be extended to query for `User`.`name`
>> instead of just `name`, since both tables have a column called  
>> `name`.
>> I'm not quite sure why Cake is doing all these queries in the first
>> place, guess it's just being extra paranoid.
>>
>> Anyway, the above mentioned bug seems to be very related, but nate
>> insists on a test case.
>> I have no idea how to write test cases for something like this, so
>> could a kind soul jump in?
>>
>> Chrs,
>> Dav
> >


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