Friday, February 25, 2011

Re: model relation problem

I set my Friend model with following relationship setting, it still doesn't work.

var $belongsTo = array(
'Follower' => array(
'className' => 'User',
'foreignKey' => 'user_id',
'conditions' => '',
'fields' => '',
'order' => ''
),
'Following' => array(
'className' => 'User',
'foreignKey' => 'friend_id',
'conditions' => '',
'fields' => '',
'order' => ''
)
);

The sql syntax error is:

Query: SELECT `Friend`.`id` FROM `friends` AS `Friend` LEFT JOIN `users` AS `User` ON (`Friend`.`user_id` = `User`.`id`) LEFT JOIN `friends` AS `Friend` ON (`Friend`.`friend_id` = `Friend`.`id`)  LIMIT 1 

According to the logic, the second left join should still be User, not Friend

What's wrong ??

On Thu, Feb 24, 2011 at 6:58 PM, Alex Ciobanu <ics.cakephp@gmail.com> wrote:
On 2/24/2011 6:54 PM, pang wrote:
The  problem is `Friend`.`friend_id` is left joined with
`Friend`.`id`. How to solve this problem ?

Give it a different alias.

E.g.:
public $belongsTo = array(
       'MyFriend' => array('className' => 'Friend',
                           'foreignKey' => 'friend_id',
       )
   );

--
Our newest site for the community: CakePHP Video Tutorials http://tv.cakephp.org Check out the new CakePHP Questions site http://ask.cakephp.org and help others with their CakePHP related questions.


To unsubscribe from this group, send email to
cake-php+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php



--
FU Yi
Lead Developer, TA Group AB
Riddargatan 17
114 57 Stockholm
www.tagroup.se

This e-mail is intended only for the addressee(s) and may contain privileged and confidential information. If you are not the intended recipient, please be notified that any distribution or copying is strictly prohibited. If you have received this e-mail in error, please notify us immediately and delete it from your system.


--
Our newest site for the community: CakePHP Video Tutorials http://tv.cakephp.org
Check out the new CakePHP Questions site http://ask.cakephp.org and help others with their CakePHP related questions.
 
 
To unsubscribe from this group, send email to
cake-php+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php

No comments: