Monday, May 31, 2010

Re: HABTM Containable find('all') question

Your double join on the same table is fine, I just didn't notice it.

Can you try this instead?

SELECT DISTINCT User.id, User.username FROM users AS User
LEFT JOIN friends AS Friend ON (User.id = Friend.user_id AND
Friend.approved IN(0,1))
LEFT JOIN friends AS Admirer ON (User.id = Admirer.friend_id AND
Admirer.approved IN(0,1))

Does this give the desired results where the Friend count is the
amount of records where friends.user_id matches the current user and
the Admirer count is the number of friends where friends.friend_id
matches the current users.

If this works and pulls the data you are sure it should pull then we
simply need to force some joins in Cake using:

http://book.cakephp.org/view/86/Creating-and-Destroying-Associations-on-the-Fly

or

http://book.cakephp.org/view/872/Joining-tables

HTH

Paul

Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions.

You received this message because you are subscribed to the Google Groups "CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
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?hl=en

No comments: