public function search() { $query = Group::find(); if ($this->name) { $query->andFilterWhere(['like', 'group.name', $this->name]); } if ($this->city_id) { $query->andFilterWhere(['group.city_id' => $this->city_id]); } if ($this->university_id) { $query->andFilterWhere(['group.university_id' => $this->university_id]); } if ($this->tag_id) { $query->leftJoin(TagToGroup::tableName() . ' AS tag', 'tag.group_id = group.id')->andFilterWhere(['tag.tag_id' => $this->tag_id]); } return $query->orderBy('group.name')->all(); }
public function getTags() { return $this->hasMany(Tag::className(), ['id' => 'tag_id'])->viaTable(TagToGroup::tableName(), ['group_id' => 'id'])->orderBy('name'); }
/** * @return \yii\db\ActiveQuery */ public function getTagToGroups() { return $this->hasMany(TagToGroup::className(), ['tag_id' => 'id']); }