Cкоуп:
Код: Выделить всё
public function createdBy($userId)
{
$a = $this->getTableAlias(false, false);
$criteria = $this->getDbCriteria();
$criteria->addCondition($a . '.user_id = ' . (int)$userId);
return $this;
}
Код: Выделить всё
$criteria = new CDbCriteria();
$criteria->scopes['createdBy'] = array('userId' => 1);
$criteria->addCondition('id <> 0'); //tmp condition
$finder = Post::model(); //finder
$finder->setDbCriteria($criteria);
$posts = $finder->findAll();
Вопрос почему не применяются скоупы?