jonny
(Jonny)
1
Hi,
I’m trying to do a join across 3 tables like so:
$model=new CActiveDataProvider('Seller', array(
'criteria' => array(
'with' => array('company','items'),
'condition' => 't.company_id IS NOT NULL AND items.date_expired > CURDATE()'
)
));
This fails Column not found: 1054 Unknown column ‘items.date_expired’
The Seller Model has both relations, the company model doesn’t have an items relation. If that would be the reason?
Post here your model’s relations method.
jonny
(Jonny)
3
Seller.php
public function relations() {
return array(
...
'items' => array(self::HAS_MANY, 'Item', 'seller_id'),
'company' => array(self::BELONGS_TO, 'Company', 'company_id'),
...
);
}
Company.php
public function relations() {
return array(
...
'seller' => array(self::HAS_MANY, 'Seller', 'company_id'),
);
}
Item.php
public function relations() {
return array(
'seller' => array(self::BELONGS_TO, 'Seller', 'seller_id'),
);
}
I’m trying to get all the Sellers and Company records where the company_id is not null and they have an item listed that hasn’t expired.
Hope that helps make a clearer picturer.