Skip to content

Commit

Permalink
[update] introduce Condition::isTraversing
Browse files Browse the repository at this point in the history
  • Loading branch information
georgehristov committed Aug 8, 2020
1 parent 030b5e0 commit e9e6dfb
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions src/Model/Scope/Condition.php
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ protected function onChangeModel(): void
// @todo: consider this when condition is part of OR scope
if ($this->operator === self::OPERATOR_EQUALS && !is_object($this->value) && !is_array($this->value)) {
// key containing '/' means chained references and it is handled in toQueryArguments method
if (is_string($field = $this->key) && !str_contains($field, '/')) {
if (is_string($field = $this->key) && !$this->isTraversing()) {
$field = $model->getField($field);
}

Expand All @@ -158,6 +158,11 @@ protected function onChangeModel(): void
}
}

protected function isTraversing()
{
return is_string($this->key) && str_contains($this->key, '/');
}

public function toQueryArguments(): array
{
if ($this->isEmpty()) {
Expand All @@ -172,7 +177,7 @@ public function toQueryArguments(): array
if (is_string($field)) {
// shorthand for adding conditions on references
// use chained reference names separated by "/"
if (str_contains($field, '/')) {
if ($this->isTraversing()) {
$references = explode('/', $field);
$field = array_pop($references);

Expand Down Expand Up @@ -263,7 +268,7 @@ protected function keyToWords(Model $model): string
$words = [];

if (is_string($field = $this->key)) {
if (str_contains($field, '/')) {
if ($this->isTraversing()) {
$references = explode('/', $field);

$words[] = $model->getModelCaption();
Expand Down Expand Up @@ -332,7 +337,7 @@ protected function valueToWords(Model $model, $value): string

// handling of scope on references
if (is_string($field = $this->key)) {
if (str_contains($field, '/')) {
if ($this->isTraversing()) {
$references = explode('/', $field);

$field = array_pop($references);
Expand Down

0 comments on commit e9e6dfb

Please sign in to comment.