本文整理匯總了PHP中yii\db\ActiveQuery::joinWith方法的典型用法代碼示例。如果您正苦於以下問題:PHP ActiveQuery::joinWith方法的具體用法?PHP ActiveQuery::joinWith怎麽用?PHP ActiveQuery::joinWith使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類yii\db\ActiveQuery
的用法示例。
在下文中一共展示了ActiveQuery::joinWith方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: setupCriteria
public function setupCriteria()
{
$this->activeQuery->joinWith('content');
$this->activeQuery->joinWith('content.createdBy');
$this->activeQuery->joinWith('content.contentContainer');
$this->activeQuery->limit($this->limit);
$this->activeQuery->andWhere(['user.status' => User::STATUS_ENABLED]);
/**
* 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.created_by != :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);
}
}
}
示例2: relation
public function relation($relation_name)
{
$relation = ModelHelper::getRelation($this->model, $relation_name);
$relationClass = $relation->modelClass;
$relationField = $relationClass::tableName() . '.' . ($relation->multiple ? array_values($relation->link)[0] : array_keys($relation->link)[0]);
$relationValue = $this->model->{$relation_name};
if ($relationValue instanceof ActiveRecord) {
$relationValue = ModelHelper::getPkColumnValue($relationValue);
}
$this->query->joinWith($relation_name)->andFilterWhere([$relationField => $relationValue]);
}
示例3: prepareRelationField
/**
* @param \yii\db\ActiveQuery $query
* @param string $field
* @return bool
* @throws BadRequestHttpException
*/
protected function prepareRelationField($query, &$field)
{
if (strpos($field, '.') === false) {
return false;
}
$model = $this->model;
$fullRelation = '';
$fieldElements = explode('.', $field);
$fieldElementsCount = count($fieldElements);
for ($i = 1; $i < $fieldElementsCount; ++$i) {
$relationName = $fieldElements[$i - 1];
$relationMethod = 'get' . ucfirst($relationName);
if (!method_exists($model, $relationMethod)) {
throw new BadRequestHttpException('Relation isn\'t exist.');
}
/** @var \yii\db\ActiveQuery $relationQuery */
$relationQuery = $model->{$relationMethod}();
/** @var \yii\db\ActiveRecord $relationModel */
$model = new $relationQuery->modelClass();
$fullRelation .= '.' . $relationName;
}
$query->joinWith(trim($fullRelation, '.'));
$attribute = $fieldElements[$fieldElementsCount - 1];
if (!$model->isAttributeSafe($attribute)) {
throw new BadRequestHttpException('Unsafe relation attribute.');
}
$field = $model::tableName() . '.' . $attribute;
return true;
}
示例4: buildElementsQuery
/**
* Конфигурирование объекта запроса поиска по элементам.
*
* @param \yii\db\ActiveQuery $activeQuery
* @param null $modelClassName
* @return $this
*/
public function buildElementsQuery(\yii\db\ActiveQuery $activeQuery)
{
$where = [];
//Нужно учитывать связанные дополнительные данные
if ($this->enabledElementProperties == Cms::BOOL_Y) {
$activeQuery->joinWith('cmsContentElementProperties');
//Нужно учитывать настройки связанные дополнительные данных
if ($this->enabledElementPropertiesSearchable == Cms::BOOL_Y) {
$activeQuery->joinWith('cmsContentElementProperties.property');
$where[] = ['and', ['like', CmsContentElementProperty::tableName() . ".value", '%' . $this->searchQuery . '%', false], [CmsContentProperty::tableName() . ".searchable" => Cms::BOOL_Y]];
} else {
$where[] = ['like', CmsContentElementProperty::tableName() . ".value", '%' . $this->searchQuery . '%', false];
}
}
//Поиск по основному набору полей
if ($this->searchElementFields) {
foreach ($this->searchElementFields as $fieldName) {
$where[] = ['like', CmsContentElement::tableName() . "." . $fieldName, '%' . $this->searchQuery . '%', false];
}
}
if ($where) {
$where = array_merge(['or'], $where);
$activeQuery->andWhere($where);
}
//Отфильтровать только конкретный тип
if ($this->searchElementContentIds) {
$activeQuery->andWhere([CmsContentElement::tableName() . ".content_id" => (array) $this->searchElementContentIds]);
}
return $this;
}
示例5: processSearchRelated
/**
* Adds a condition to search in relations using subquery.
* @todo this should be called for each token, to group their conditions with OR and group token groups with AND
*
* @param \yii\db\ActiveQuery $query
* @param array $tokens all search tokens extracted from term
* @param array $relationAttributes array of string(relation name) => array(
* 'model' => netis\crud\db\ActiveRecord,
* 'searchModel' => netis\crud\db\ActiveSearchTrait,
* 'attributes' => array
* )
* @return array conditions to add to $query
*/
protected function processSearchRelated(\yii\db\ActiveQuery $query, array $tokens, array $relationAttributes)
{
$allConditions = ['or'];
foreach ($relationAttributes as $relationName => $relation) {
/**
* @todo optimize this (check first, don't want to loose another battle with PostgreSQL query planner):
* - for BELONGS_TO check fk against subquery
* - for HAS_MANY and HAS_ONE check pk against subquery
* - for MANY_MANY join only to pivot table and check its fk agains subquery
*/
$query->joinWith([$relationName => function ($query) use($relationName) {
/** @var \yii\db\ActiveQuery $query */
/** @var \yii\db\ActiveRecord $class */
$class = $query->modelClass;
return $query->select(false)->from([$relationName => $class::tableName()]);
}]);
$conditions = ['and'];
/** @var ActiveSearchInterface $searchModel */
$searchModel = $relation['searchModel'];
if (!$searchModel instanceof ActiveSearchInterface) {
continue;
}
foreach ($tokens as $token) {
$condition = $searchModel->processSearchToken($token, $relation['attributes'], $relationName);
if ($condition !== null) {
$conditions[] = $condition;
}
}
if ($conditions !== ['and']) {
$allConditions[] = $conditions;
}
}
return $allConditions !== ['or'] ? $allConditions : null;
}