Thanks so much for getting back to me. I can tell you I have learned
a lot from your posts since I have started using cake so thank you.
Here is the sql statement:
23 SELECT `User`.`id`, `User`.`username`, `User`.`first_name`,
`User`.`last_name`, `User`.`city`, `User`.`state`, `User`.`country`,
`User`.`created`, `UserPreference`.`image` FROM `users` AS `User` LEFT
JOIN `user_preferences` AS `UserPreference` ON
(`UserPreference`.`user_id` = `User`.`id`) WHERE `User`.`id` != 4
ORDER BY `User`.`first_name` asc LIMIT 15
24 SELECT `friend`.`id`, `Friend`.`id`, `Friend`.`user_id`,
`Friend`.`friend_id`, `Friend`.`approved`, `Friend`.`message`,
`Friend`.`created`, `Friend`.`modified` FROM `users` AS `friend` JOIN
`friends` AS `Friend` ON (`Friend`.`user_id` IN (3, 28, 29, 5) AND
`Friend`.`friend_id` = `friend`.`id`) WHERE `friend`.`id` = 4 AND
`Friend`.`approved` != -1
25 SELECT `admirer`.`id`, `admirer`.`created`, `Friend`.`id`,
`Friend`.`user_id`, `Friend`.`friend_id`, `Friend`.`approved`,
`Friend`.`message`, `Friend`.`created`, `Friend`.`modified` FROM
`users` AS `admirer` JOIN `friends` AS `Friend` ON
(`Friend`.`friend_id` IN (3, 28, 29, 5) AND `Friend`.`user_id` =
`admirer`.`id`) WHERE `admirer`.`id` = 4 AND `Friend`.`approved` !=
-1
So, the USER record is showing up and the FRIEND array is not so
actually it is right. However, I just want the USER records who's
Friend.approved == 0 or 1.
I put Friend.approved in the main conditions of the find() and it
comes back with a 1054 Unknown Column error:)
Thanks in advance.
Brad
On May 26, 12:13 am, WebbedIT <p...@webbedit.co.uk> wrote:
> Have you debugged the sql queries (set debug to 2) to work out where
> the sql is not being generated correctly as the condition in principle
> looks correct.
>
> Maybe just typos but a few things look off
>
> 'Friend' => array(
> 'conditions' => array(
> 'Friend.id =' => $this->Auth->user('id'),
> 'Friend.approved !=' => '-1'
> )
> ),
> 'Admirer' => array(
> 'conditions' => array(
> 'Admirer.id =' => $this->Auth->user('id'),
> 'Friend.approved !=' => '-1'
> )
> ),
>
> Friend and Admirer should be referenced with capital first letters and
> there's no need to wrap conditions in AND array as that is what is
> used by default.
>
> HTH
>
> Paul.
>
> On May 26, 1:28 am, bradmaxs <b...@pezzano.com> wrote:
>
> > Hello,
>
> > I am working on a HABTM relationship.
>
> > Here is my controller action:
>
> > function index() {
> > $this->User->Behaviors->attach('Containable');
> > $this->paginate = array(
> > 'contain' => array(
> > 'friend' => array(
> > 'conditions' => array(
> > 'friend.id =' => $this->Auth->user('id'),
> > )
> > ),
> > 'admirer' => array(
> > 'conditions' => array(
> > 'admirer.id =' => $this->Auth->user('id'),
> > )
> > ),
> > 'UserPreference.image'
> > ),
> > 'conditions' => array(
> > 'User.id !=' => $this->Auth->user('id')
> > ),
> > 'recursive' => true,
> > 'limit' => 15,
> > 'order' => array(
> > 'User.first_name' => 'asc'
> > )
> > );
> > $users = $this->paginate('User');
> > $this->set(compact('users'));
> > }
>
> > In my User model:
>
> > var $hasAndBelongsToMany = array(
> > 'friend' => array('className' => 'User',
> > 'joinTable' => 'Friend',
> > 'foreignKey' => 'user_id',
> > 'associationForeignKey' => 'friend_id'
> > ),
> > 'admirer' => array('className' => 'User',
> > 'joinTable' =>'Friend',
> > 'foreignKey' => 'friend_id',
> > 'associationForeignKey' => 'user_id')
> > );
>
> > I have a column in the Friend table that has approved which is by
> > default 0. When someone approves, they get a 1 and if someone rejects
> > they get a -1.
>
> > In my index view I would like to exclude all Friend.approved => -1.
>
> > Here is the dump:
>
> > Array
> > (
> > [0] => Array
> > (
> > [id] => 4
> > [username] => xxx
> > [password] => xxx
> > [first_name] => xxx
> > [last_name] => xxx
> > [street_address] => xxx
> > [city] => xxx
> > [state] => xxx
> > [zip] => xxx
> > [country] => xxx
> > [telephone] => xxx
> > [email_address] => xxx
> > [group_id] => xxx
> > [created] => 2010-05-03 17:33:54
> > [updated] => 2010-05-14 15:57:10
> > [Friend] => Array
> > (
> > [id] => 39
> > [user_id] => 4
> > [friend_id] => 29
> > [approved] => -1
> > [message] =>
> > [created] => 2010-05-22 12:44:05
> > [modified] => 2010-05-25 13:15:49
> > )
>
> > )
>
> > )
>
> > If I put:
>
> > 'friend' => array(
> > 'conditions' => array(
> > 'AND' => array(
> > 'friend.id =' => $this->Auth->user('id'),
> > 'Friend.approved !=' => '-1'
> > )
> > )
> > ),
> > 'admirer' => array(
> > 'conditions' => array(
> > 'AND' => array(
> > 'admirer.id =' => $this->Auth->user('id'),
> > 'Friend.approved !=' => '-1'
> > )
> > )
> > ),
>
> > I get this:
>
> > Array
> > (
> > )
>
> > So the user is still showing up, and it seems that the array is just
> > not getting any info. I want to EXCLUDE the users who have a
> > Friend.approved = -1.
>
> > Anyone know any solutions. I thought making a sub query but it seems
> > like it might be too much for this final exclusion. Not to mention I
> > have worked so hard just to get here (although learning every step of
> > the way) I don't want to mess with what I have got because the
> > pagination works with it.
>
> > Any help would be great.
>
> > Thanks,
>
> > Brad
>
>
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:
Post a Comment