Skip to content

Commit

Permalink
Fix anonymous class detection (#854)
Browse files Browse the repository at this point in the history
* Fix anonymous class detection

* Fix next ver

* small refactor
  • Loading branch information
mvorisek authored Apr 19, 2021
1 parent 303be75 commit 736d340
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 6 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
"require-release": {
"php": ">=7.3.0",
"ext-intl": "*",
"atk4/dsql": "~2.4.0",
"atk4/dsql": "~2.5.0",
"mahalux/atk4-hintable": "~1.2.1"
},
"conflict": {
Expand Down
2 changes: 1 addition & 1 deletion src/Model.php
Original file line number Diff line number Diff line change
Expand Up @@ -854,7 +854,7 @@ public function setId($value)
public function getModelCaption(): string
{
return $this->caption ?: $this->readableCaption(
strpos(static::class, 'class@anonymous') === 0 ? get_parent_class(static::class) : static::class
(new \ReflectionClass(static::class))->isAnonymous() ? get_parent_class(static::class) : static::class
);
}

Expand Down
11 changes: 7 additions & 4 deletions src/Persistence/Sql.php
Original file line number Diff line number Diff line change
Expand Up @@ -364,12 +364,15 @@ protected function setLimitOrder(Model $model, Query $query)
}

/**
* Will apply a condition defined inside $condition or $model->scope() onto $query.
* Will apply $model->scope() conditions onto $query.
*/
public function initQueryConditions(Model $model, Query $query, Model\Scope\AbstractScope $condition = null): void
public function initQueryConditions(Model $model, Query $query): void
{
$condition = $condition ?? $model->scope();
$this->_initQueryConditions($query, $model->scope());
}

private function _initQueryConditions(Query $query, Model\Scope\AbstractScope $condition = null): void
{
if (!$condition->isEmpty()) {
// peel off the single nested scopes to convert (((field = value))) to field = value
$condition = $condition->simplify();
Expand All @@ -384,7 +387,7 @@ public function initQueryConditions(Model $model, Query $query, Model\Scope\Abst
$expression = $condition->isOr() ? $query->orExpr() : $query->andExpr();

foreach ($condition->getNestedConditions() as $nestedCondition) {
$this->initQueryConditions($model, $expression, $nestedCondition);
$this->_initQueryConditions($expression, $nestedCondition);
}

$query->where($expression);
Expand Down

0 comments on commit 736d340

Please sign in to comment.