Yii Framework Forum: Findall In Relational Tables With != Condition - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Findall In Relational Tables With != Condition Rate Topic: -----

#1 User is offline   reader 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 6
  • Joined: 07-March 12

Posted 19 December 2012 - 10:24 AM

Hi all......

I have two tables jobStatus and notifiactionRules, structures of tables are:

JobStatus:

id : PK
name

notifiactionRules

id : PK
status_id : FK

i want to write a condition in findAll, such that i have to get the names of all job status that are NOT IN notifiactionRules.

I tried this:

$jobstatuslist = CHtml::listData(JobStatus::model()
->findAll(array(
'condition'=>'id!=:status_id',
'params'=>array(':status_id'=>NotificationRules::model()->findAll(),'id', 'job_status_id'))
));

but i am getting error - Undefined offset: 2

can anyone pls help.......
0

#2 User is offline   KonApaz 

  • Elite Member
  • PipPipPipPipPip
  • Yii
  • Group: Members
  • Posts: 1,332
  • Joined: 21-February 11
  • Location:Greece

Posted 20 December 2012 - 04:29 AM

Hi "reader"

check something like that

YourAR1::model()->findAll(array(
'condition' => YourAR2::model()->exists( 't1.id = t2.status_id')->findAll()
))
Yii is the best php framework in the world!
find our demo Yii extension on www.webkit.gr
Is it post useful? please v++ ;)
0

#3 User is offline   ragua 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 135
  • Joined: 23-January 12
  • Location:Paris - France

Posted 20 December 2012 - 04:57 AM

Hi,
you can also use SQL in findall, for instance in postgresql it would be something like
...::model()->findAll(array('condition'=> "not exists (select 'a' from notifiactionRules where notifiactionRules.status_id = JobStatus.id)"));

1

#4 User is offline   reader 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 6
  • Joined: 07-March 12

Posted 20 December 2012 - 05:08 AM

Hi ragua,

Thanks alot....... it works perfect...... thanks again...... :)
0

#5 User is offline   KonApaz 

  • Elite Member
  • PipPipPipPipPip
  • Yii
  • Group: Members
  • Posts: 1,332
  • Joined: 21-February 11
  • Location:Greece

Posted 20 December 2012 - 04:48 PM

View PostKonApaz, on 20 December 2012 - 04:29 AM, said:

Hi "reader"

check something like that

YourAR1::model()->findAll(array(
'condition' => YourAR2::model()->exists( 't1.id = t2.status_id')->findAll()
))


I misunderstood 'not exist ' by 'exists' so ragua solution is the correct :)
Yii is the best php framework in the world!
find our demo Yii extension on www.webkit.gr
Is it post useful? please v++ ;)
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users