There are many comparators in QueryBuilder, but I can’t find simple ‘equals’ (x = y).
In all tutorials on www [including doc-2.0] is this code to compare column and value:
$query->andFilterWhere(['something' => $someValue]);
And this code to compare with other comparators:
$query->andFilterWhere(['like', 'something', $someValue]);
When I try:
$query->andFilterWhere(['=', 'something', $someValue]);
or:
$query->andFilterWhere(['equals', 'something', $someValue]);
It throws exception.
How my code looks now:
class Xyz extends ActiveRecord {
...
public static function fieldsSearchConfig() {
return [
'name' => 'like',
'license_id' => '='
];
}
public function getActiveQuery($params) {
$activeQuery = WiatrakiX::find()->with('nazwaMiasta');
if (!($this->load($params) && $this->validate())) {
return $activeQuery;
}
foreach(self::fieldsSearchConfig() as $fieldName => $fieldComparator) {
// BAD PART
if($fieldComparator == '=') {
$condition = [$fieldName => $this->$fieldName];
} else {
$condition = [$fieldComparator, $fieldName, $this->$fieldName];
}
// BAD PART END
if(self::$searchType == self::SEARCH_AND) {
$activeQuery->andFilterWhere($condition);
} else {
$activeQuery->orFilterWhere($condition);
}
}
}
}
How it should be:
class Xyz extends ActiveRecord {
...
public static function fieldsSearchConfig() {
return [
'name' => 'like',
'license_id' => '='
];
}
public function getActiveQuery($params) {
$activeQuery = WiatrakiX::find()->with('nazwaMiasta');
if (!($this->load($params) && $this->validate())) {
return $activeQuery;
}
foreach(self::fieldsSearchConfig() as $fieldName => $fieldComparator) {
$condition = [$fieldComparator, $fieldName, $this->$fieldName];
if(self::$searchType == self::SEARCH_AND) {
$activeQuery->andFilterWhere($condition);
} else {
$activeQuery->orFilterWhere($condition);
}
}
}
}
Is there any way to make it works nice (and I’m just stupid/blind) or I must wait for Yii2 update?
Second question:
Are you going to add features from some Yii2 extensions [Editable Grid, DynaGrid] to final release or you want keep them as extensions?