diff --git a/src/Model/Scope/CompoundCondition.php b/src/Model/Scope/CompoundCondition.php index 5c550c3524..7173b13590 100644 --- a/src/Model/Scope/CompoundCondition.php +++ b/src/Model/Scope/CompoundCondition.php @@ -68,6 +68,22 @@ public function __clone() } } + /** + * Add nested condition. + * + * @param mixed $field + * @param mixed $operator + * @param mixed $value + * + * @return static + */ + public function addCondition($field, $operator = null, $value = null) + { + $this->add(static::createAnd([func_get_args()])); + + return $this; + } + /** * Return array of nested conditions. * diff --git a/tests/ScopeTest.php b/tests/ScopeTest.php index b04cecf9f7..4098e83924 100644 --- a/tests/ScopeTest.php +++ b/tests/ScopeTest.php @@ -298,9 +298,9 @@ public function testScope() $this->assertEquals($compoundCondition->toWords($user), $user->scope()->toWords()); - $condition5 = new BasicCondition('country_code', 'BR'); + $compoundCondition = CompoundCondition::createOr($compoundCondition1, $compoundCondition2); - $compoundCondition = CompoundCondition::createOr($compoundCondition1, $compoundCondition2, $condition5); + $compoundCondition->addCondition('country_code', 'BR'); $this->assertEquals('(Name is equal to \'John\' and Code is equal to \'CA\') or (Surname is equal to \'Doe\' and Code is equal to \'LV\') or Code is equal to \'BR\'', $compoundCondition->toWords($user));