當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Query::create方法代碼示例

本文整理匯總了PHP中yii\db\Query::create方法的典型用法代碼示例。如果您正苦於以下問題:PHP Query::create方法的具體用法?PHP Query::create怎麽用?PHP Query::create使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在yii\db\Query的用法示例。


在下文中一共展示了Query::create方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: prepare

 /**
  * @inheritdoc
  */
 public function prepare($builder)
 {
     // NOTE: because the same ActiveQuery may be used to build different SQL statements
     // (e.g. by ActiveDataProvider, one for count query, the other for row data query,
     // it is important to make sure the same ActiveQuery can be used to build SQL statements
     // multiple times.
     if (!empty($this->joinWith)) {
         $this->buildJoinWith();
         $this->joinWith = null;
         // clean it up to avoid issue https://github.com/yiisoft/yii2/issues/2687
     }
     if (empty($this->from)) {
         /* @var $modelClass ActiveRecord */
         $modelClass = $this->modelClass;
         $tableName = $modelClass::tableName();
         $this->from = [$tableName];
     }
     if (empty($this->select) && !empty($this->join)) {
         list(, $alias) = $this->getQueryTableName($this);
         $this->select = ["{$alias}.*"];
     }
     if ($this->primaryModel === null) {
         // eager loading
         $query = Query::create($this);
     } else {
         // lazy loading of a relation
         $where = $this->where;
         if ($this->via instanceof self) {
             // via junction table
             $viaModels = $this->via->findJunctionRows([$this->primaryModel]);
             $this->filterByModels($viaModels);
         } elseif (is_array($this->via)) {
             // via relation
             /* @var $viaQuery ActiveQuery */
             list($viaName, $viaQuery) = $this->via;
             if ($viaQuery->multiple) {
                 $viaModels = $viaQuery->all();
                 $this->primaryModel->populateRelation($viaName, $viaModels);
             } else {
                 $model = $viaQuery->one();
                 $this->primaryModel->populateRelation($viaName, $model);
                 $viaModels = $model === null ? [] : [$model];
             }
             $this->filterByModels($viaModels);
         } else {
             $this->filterByModels([$this->primaryModel]);
         }
         $this->_viaModels = !empty($viaModels) ? $viaModels : [];
         $query = Query::create($this);
         $this->where = $where;
     }
     if (!empty($this->on)) {
         $query->andWhere($this->on);
     }
     return $query;
 }
開發者ID:alexinator1,項目名稱:yii2-jta,代碼行數:59,代碼來源:ActiveQuery.php

示例2: relations

 public function relations($model, $attribute)
 {
     $relation = $model->fileRelation($attribute);
     $handlerRelationQuery = $model->fileOption($attribute, 'relationQuery');
     $query = null;
     if ($handlerRelationQuery) {
         $query = Query::create($handlerRelationQuery($model->find()));
     }
     $query = $query ?: new Query();
     return $query->from($relation->via->from[0])->andWhere([key($relation->via->link) => $model->getPrimaryKey()])->indexBy(current($relation->link))->all();
 }
開發者ID:rkit,項目名稱:filemanager-yii2,代碼行數:11,代碼來源:FileBind.php


注:本文中的yii\db\Query::create方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。