ItGo.me Focus on IT Recommend

Home > has and belongs to many - Cakephp retrieve data in HABTM association

has and belongs to many - Cakephp retrieve data in HABTM association

2020腾讯云双十一活动,全年最低!!!(领取3500元代金券),
地址https://cloud.tencent.com/act/cps/redirect?redirect=1074

【阿里云】双十一活动,全年抄底价,限时3天!(老用户也有),
入口地址https://www.aliyun.com/1111/home

I have 2 tables subscribers and distribution list and the relationship between them is HABTM. Now here particular users are associated to distribution list, i wish to add more users, but when adding new users to distribution list, i would like to show users who are not associated with that distribution lists. what condition should i write

cakephp has-and-belongs-to-many
|
  this question
asked Sep 20 '10 at 10:15 Avinash 11 1      Use a NOT IN() –  David Yell Sep 20 '10 at 14:50      NOT IN will only give me subscribers which are not belonging any of the distribution list –  Avinash Sep 23 '10 at 6:28

 | 

1 Answers
1

$this->DistributionSubscriber->find('list', array('conditions'=>array('distribution_id <>' => 1), 'fields'=>array('subscriber_id'), 'recursive'=>-1));

I would try something like this. You want to start with the join table in this case, and do your find() from there. I haven't checked this syntax, but you should get the idea.


|
  this answer
answered Sep 21 '10 at 22:07 Dooltaz 1,718 1 9 14      this would give me list of subscribers which are NOT there in the distribution list but rest of the entries in that join table –  Avinash Sep 23 '10 at 6:29

 | 

Recommend:has and belongs to many - CakePHP find HABTM

e Message belongsto User Message HABTM Tag Tag HABTM Message If a User is logged in he might want to see all Message tagged with something. $messages = $this->Message->find('all', array( 'conditions' => array("Message.user_id" => $this-

------splitte line----------------------------