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