Есть таблица заявки - statement.
Есть таблица - statement_history в которой есть поля status, user_id, statement_id.
Тоесть мне необходимо выбрать заявки - модель Statement, по 'user_id' и где статус 'created'. Модели CActiveRecord для statement_history нет.
На голом SQL запрос такой получается(вроде рабочий )
Код: Выделить всё
SELECT * FROM `statement` INNER JOIN `statement_history` ON `statement_history`.`statement_id` = `statement`.`id` WHERE `statement_history`.`status` = 'created' AND `statement_history`.`user_id` = ?
Код: Выделить всё
/**
* Вывод заявок в панели "Заявки"
* @return CActiveDataProvider
*/
public function searchlist()
{
$criteria = new CDbCriteria;
$criteria->compare('number', $this->number);
$criteria->compare('fio', $this->fio, true);
$criteria->compare('organisation_name', $this->organisation_name, true);
$criteria->compare('organisation_inn', $this->organisation_inn, true);
$criteria->compare('organisation_region_id', $this->organisation_region_id);
$criteria->compare('organisation_city_id', $this->organisation_city_id);
// Не показывать скрытые (по-умолчанию)
//$criteria->compare('statement.hidden', (isset($this->hidden) ? $this->hidden : 0));
if ($this->date_create_start != -1) {
$criteria->compare('date_create', '>=' . $this->date_create_start);
}
if ($this->date_create_end != -1) {
$criteria->compare('date_create', '<=' . ($this->date_create_end + 86400));
}
if (isset($_GET['StatementModel']['status'])) {
if (count($_GET['StatementModel']['status'])) {
$statuses = array();
foreach ($_GET['StatementModel']['status'] as $s) {
$statuses[] = '"' . $s . '"';
}
$criteria->condition = ' t.status IN (' . implode(',', $statuses) . ') ';
} else {
$criteria->condition = ' 1 ';
}
}
/* if ($_GET['StatementModel']['creator_id']) {
$criteria->join = "INNER JOIN `statement_history` ON `statement_history`.`statement_id` = `statement`.`id`
WHERE `statement_history`.`status` = 'created' AND `statement_history`.`user_id` = 1";
}*/
/* if (UserHelper::_('region_id')) {
$criteria->condition .= ' AND t.organisation_region_id=' . UserHelper::_('region_id');
}*/
return new CActiveDataProvider($this, array(
'criteria' => $criteria,
'pagination' => array(
'pageSize' => Yii::app()->modules['panels']['params']['item_per_page'], // количество записей на странице
),
'sort' => array(
'defaultOrder' => array(
'date_create' => CSort::SORT_DESC,
)
)
));
}