Saturday, December 27, 2008

Re: How would I write this query

Assuming that translates to:

SELECT
Friend.*,
User.username,
User.avatar,
User.handler
FROM
friends AS Friend,
INNER JOIN users AS User
ON User.id = Friend.user_id
WHERE
Friend.status = 'approved' AND
(
(Friend.user_id = ':user_id') OR
(User.friend_id = ':user_id')
)
ORDER BY
Friend.requestTime ASC
LIMIT 0,5


I believe this may work, of course I haven't tested it, you may want
to read [1] and [2] to make the appropriate mods:

$condition = array (
"Friend.status" => "approved",
"or" => array (
"Friend.user_id" => $user_id,
"User.friend_id >" => $user_id
)
)

$this->Friend->bindModel(array(
'hasAndBelongsToMany' => array(
'FilterUsers' => array(
'className' => 'User',
'foreignKey' => false,
'conditions' => $conditions
))));

$this->Friend->find('all');

[1] http://book.cakephp.org/view/74/Complex-Find-Conditions
[2] http://book.cakephp.org/view/83/hasAndBelongsToMany-HABTM

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