Hello I would like to do a search on an attribute of my model that references the other model how to do?
I have the following code
model:
public function relations() {
return array(
'pessoadest'=>array(self::BELONGS_TO,'pessoa','cliente',
'select'=>'nome',
'joinType'=>'INNER JOIN',
'alias'=>'pessoadest'
),
'mensagem'=>array(self::HAS_ONE,'mensagem','protocolo,empresa',
'together'=>True,
'joinType'=>'INNER JOIN',
'order'=>'??.dtenvio DESC',
'alias'=>'mensagem'
),
);
}
Controller :
public function actionAdmin() {
$this->processAdminCommand();
$criteria=new CDbCriteria;
$criteria->condition ='(protocolo.empresa='.Yii::app()->user->pessoa;
if($_REQUEST['cliente'] != "") {
$criteria->condition .= " AND pessoadest.nome LIKE '%".$_REQUEST['cliente']."%'";
}
if ($_REQUEST['situacao'] == mensagem::SFinalizada) {
$criteria->condition .=" and mensagem.situacao = 'Finalizada' ";
}
$pages=new CPagination(protocolo::model()->with('tpprotocolo','pessoadest','mensagem')->count($criteria));
$pages->pageSize=self::PAGE_SIZE;
$pages->applyLimit($criteria);
$sort=new CSort('protocolo');
$sort->attributes= array(
'tpprotocolo.nome'=>'tpprotocoloNome',
'pessoadest.nome'=>'pessoadestNome'
);
$sort->defaultOrder='protocolo.protocolo DESC';
$sort->multiSort=false;
$sort->applyOrder($criteria);
$protocoloList=protocolo::model()->with('tpprotocolo','pessoadest','mensagem')->findAll($criteria);
$this->render('admin',array(
'protocoloList'=>$protocoloList,
'pages'=>$pages,
'sort'=>$sort,
));
}
as I have a primary key made up the count do not I was running the following alterations
class CJoinElement
...
public function count($criteria=null){
...
else if (is_array($this->_table->primaryKey))
{
$prefix=$this->getColumnPrefix();
$schema=$this->_builder->getSchema();
$pk=array();
foreach($this->_table->primaryKey as $name)
$pk[$name]=$prefix.$schema->quoteColumnName($name);
$column =implode(' , ', $pk);
$query->selects=array("COUNT(DISTINCT $column)");
}
...
brought with it the count correctly but when do the sorting or paging him ta get lost in the amount of records
would like suggestions on how to address this issue