/**
  * @return ActiveQuery
  * @throws ErrorException
  */
 public function getNavAssignment()
 {
     if (!$this instanceof ActiveRecord) {
         throw new ErrorException(__CLASS__ . ' is not instance of yii\\db\\ActiveRecord.');
     }
     /** @var ActiveRecord $this */
     return $this->hasOne(Assignment::className(), ['assignment' => 'id'])->orderBy('type ASC');
 }
Esempio n. 2
0
 /**
  * @param integer $userId
  * @param string $widget
  * @param null|string $route
  * @return null|ActiveRecord
  */
 public static function findByAssignment($userId, $widget, $route = null)
 {
     return static::find()->innerJoinWith(['assignments' => function (ActiveQuery $query) {
         $query->from(['assignment' => Assignment::tableName()]);
     }])->andWhere('`assignment`.`user_id` = :user_id')->andWhere('`assignment`.`widget` = :widget')->andWhere('`assignment`.`route` = :route OR `assignment`.`route` IS NULL')->params([':user_id' => $userId, ':widget' => $widget, ':route' => $route])->orderBy(['assignment.route' => SORT_DESC, 'assignment.id' => SORT_DESC])->one();
 }