transistor
(Jlsistemas)
February 28, 2010, 9:11am
1
I have the following tables:
I need to select items from table3 with a condition involving table1.
$condition = 'table1.someField = someValue';
$anuncios = new CActiveDataProvider('anuncio', array(
'criteria'=>array(
'condition'=>$condition,
// I am using table 2 also, so:
'with'=>'table2',
'together'=>true,
),
'pagination'=>array(
'pageSize'=>self::PAGE_SIZE,
),
'sort'=>$sort,
));
Of course, this doesn’t work, I get an error: SQLSTATE[42S22]: Column not found: 1054 Unknown column ‘table1.someField’ in ‘where clause’
Can you help me?
What am I missing here?
Thanks
bettor
(Live Webscore)
February 28, 2010, 9:22am
2
I need to select items from table3 with a condition involving table1.
$condition = 'table1.someField = someValue';
$anuncios = new CActiveDataProvider('anuncio', array(
'criteria'=>array(
'condition'=>$condition,
// I am using table 2 also, so:
'with'=>'table2',
'together'=>true,
),
'pagination'=>array(
'pageSize'=>self::PAGE_SIZE,
),
'sort'=>$sort,
));
Of course, this doesn’t work, I get an error: SQLSTATE[42S22]: Column not found: 1054 Unknown column ‘table1.someField’ in ‘where clause’
Can you help me?
What am I missing here?
Thanks
…what table name has been declared in your ‘anuncio’ model? … also would be very helpful to paste the relation function here to see what you’ve declared there.
bettor
transistor
(Jlsistemas)
February 28, 2010, 7:41pm
3
@bettor : sorry, my mistake. Instead of anuncio it should be table3
$condition = 'table1.someField = someValue';
$anuncios = new CActiveDataProvider('table3', array(
'criteria'=>array(
'condition'=>$condition,
// I am using table 2 also, so:
'with'=>'table2',
'together'=>true,
),
'pagination'=>array(
'pageSize'=>self::PAGE_SIZE,
),
'sort'=>$sort,
));
The relation defined in the models are:
Table3:
'table2' => array(self::BELONGS_TO, 'table2', 'id'),
Table2:
'table3' => array(self::HAS_MANY, 'table3', 'table_2'),
'table1' => array(self::BELONGS_TO, 'table1', 'id'),
Table1:
'table2' => array(self::HAS_MANY, 'table2', 'id'),
I want to have this condition:
table1.someField = someValue
How can I do this?
Thanks
Sorry for the bump
I haven’t figured this one out.
jsoo
(Jeff)
March 9, 2010, 11:44am
6
Guess from a Yii noob:
'with' => array(
'table2',
'table2.table1'
),
or maybe:
$condition = 'table2.table1.someField = someValue';
i have a similar problem. with() for HAS_MANY relation does not seem to work with cactivedataprovider. i found a solution by reading this thread.
http://www.yiiframework.com/forum/index.php?/topic/7420-undestanding-relational-queries-with-cactivedataprovider/ "
i hope it works for you too.
jsoo:
Guess from a Yii noob:
'with' => array(
'table2',
'table2.table1'
),
or maybe:
$condition = 'table2.table1.someField = someValue';
i had a similar problem. the with() association for HAS_MANY relation does not seem to work with cactivedataprovider. i found a solution by reading this thread.
http://www.yiiframework.com/forum/index.php?/topic/7420-undestanding-relational-queries-with-cactivedataprovider/ "
i hope it works for you too.
jsoo:
Guess from a Yii noob:
'with' => array(
'table2',
'table2.table1'
),
or maybe:
$condition = 'table2.table1.someField = someValue';