one() public method

Executes query and returns a single row of result.
public one ( Connection | null $db = null ) : ActiveRecord | array | null
$db Connection | null the DB connection used to create the DB command. If `null`, the DB connection returned by [[modelClass]] will be used.
return ActiveRecord | array | null a single row of query result. Depending on the setting of [[asArray]], the query result may be either an array or an ActiveRecord object. `null` will be returned if the query results in nothing.
コード例 #1
0
 public static function getActiveToken($token)
 {
     $activeQuery = new ActiveQuery(self::className());
     $activeQuery->where('access_token = :token', [':token' => $token]);
     $activeQuery->andWhere('expires > now()');
     $token = $activeQuery->one();
     return $token;
 }
コード例 #2
0
 /**
  * @inheritdoc
  */
 public function one($db = null)
 {
     $row = parent::one($db);
     if ($row !== null && $this->isMappableQuery()) {
         /** @var ActiveRecord|ActiveRecordTrait $className */
         $className = $this->modelClass;
         $className::addRowToMap($row);
     }
     return $row;
 }
コード例 #3
0
ファイル: AddressQuery.php プロジェクト: study-code/yii2
 /**
  * @inheritdoc
  * @return Country|array|null
  */
 public function one($db = null)
 {
     $memKey = 'mofei';
     $result = Yii::$app->cache->get($memKey);
     if ($this->isCache && !empty($result)) {
         return $result;
     } else {
         $result = parent::one($db);
         if (!empty($result)) {
             Yii::$app->cache->set($memKey, $result, 5);
         }
         return $result;
     }
 }
コード例 #4
0
ファイル: Stream.php プロジェクト: alefernie/intranet
 public function setupCriteria()
 {
     $this->activeQuery->joinWith('content');
     $this->activeQuery->joinWith('content.user');
     $this->activeQuery->joinWith('content.space');
     $this->activeQuery->limit($this->limit);
     $this->activeQuery->andWhere(['user.status' => User::STATUS_ENABLED]);
     $this->activeQuery->one();
     /**
      * Handle Stream Mode (Normal Stream or Activity Stream)
      */
     if ($this->mode == self::MODE_ACTIVITY) {
         $this->activeQuery->andWhere(['content.object_model' => \humhub\modules\activity\models\Activity::className()]);
         // Dont show own activities
         if ($this->user != null) {
             $this->activeQuery->leftJoin('activity', 'content.object_id=activity.id AND content.object_model=:activityModel', ['activityModel' => \humhub\modules\activity\models\Activity::className()]);
             $this->activeQuery->andWhere('content.user_id != :userId', array(':userId' => $this->user->id));
         }
     } else {
         $this->activeQuery->andWhere(['!=', 'content.object_model', \humhub\modules\activity\models\Activity::className()]);
     }
     /**
      * Setup Sorting
      */
     if ($this->sort == self::SORT_UPDATED_AT) {
         $this->activeQuery->orderBy('wall_entry.updated_at DESC');
         if ($this->from != "") {
             $this->activeQuery->andWhere("wall_entry.updated_at < (SELECT updated_at FROM wall_entry wd WHERE wd.id=" . $this->from . ")");
         }
     } else {
         $this->activeQuery->orderBy('wall_entry.id DESC');
         if ($this->from != "") {
             $this->activeQuery->andWhere("wall_entry.id < " . $this->from);
         }
     }
 }
コード例 #5
0
 /**
  * @inheritdoc
  * @return Progressjobdetail|array|null
  */
 public function one($db = null)
 {
     return parent::one($db);
 }
コード例 #6
0
ファイル: ActiveQuery.php プロジェクト: nfilin/yii2-libs
 /**
  * @param Connection $db
  * @return ActiveRecord|null
  */
 public function one($db = null)
 {
     $row = parent::one($db);
     return $row;
 }
コード例 #7
0
ファイル: Searcher.php プロジェクト: pbabilas/bcode
 /**
  * @return static|null ActiveRecord instance matching the condition, or `null` if nothing matches.
  */
 public function findOne()
 {
     return $this->query->one();
 }