Hi
I do multiple calls to model() to feed into a dataprovider:
$provider=Data::model()->item($item);
$dataprovider = new CActiveDataProvider(
$provider,
array(
'criteria' => array('order'=>'DATETIME ASC'),
'pagination' => array('pageSize'=>$countperpage),
)
);
Inside the ‘Data’ class which extends CActiveRecord, we have
public function item($item) {
$this->getDbCriteria()->compare('ITEM',$item);
return $this;
}
In the second call the compare criteria gets added to the first and hence no more results are returned.
The criteria (as an array) looks like this after the second call:
Criteria .array
(
'select' => '*'
'condition' => '(ITEM=:ycp0) AND (ITEM=:ycp1)'
'params' => array
(
':ycp0' => '100036'
':ycp1' => '100038'
)
'limit' => -1
'offset' => -1
'order' => ''
'group' => ''
'join' => ''
'having' => ''
'distinct' => false
'scopes' => null
'with' => null
'alias' => null
'index' => null
'together' => null
)
You can see that ‘ITEM’ must correspond to two keys.
Am I using ‘model()’ in the wrong way? Is this a bug?
Under the hood the (static) model is fetched from cache, so the criteria are maintained.
I’ve added
Data::model()->setDbCriteria(null);
to reset the criteria (which works).
I would expect that ‘Data::model()’ allows me to start with empty criteria without having to do the above trick.
Any suggestion?