diff --git a/src/Queries/BaseQuery.php b/src/Queries/BaseQuery.php index e5dba1e..5165805 100644 --- a/src/Queries/BaseQuery.php +++ b/src/Queries/BaseQuery.php @@ -565,4 +565,9 @@ public function __call($method, $parameters) throw new BadMethodCallException("Call to undefined method {$className}::{$method}()"); } + + protected function prepareMultiFilter(&$key, &$value) + { + + } } diff --git a/src/Queries/BaseRelationQuery.php b/src/Queries/BaseRelationQuery.php index bd498a7..57ec3b0 100644 --- a/src/Queries/BaseRelationQuery.php +++ b/src/Queries/BaseRelationQuery.php @@ -115,8 +115,14 @@ protected function filterByModels($models) if (preg_match('/^PROPERTY_(.*)_VALUE$/', $primary, $matches) && !empty($matches[1])) { $primary = 'PROPERTY_' . $matches[1]; } + $values = array_unique($values, SORT_REGULAR); + if (count($values) == 1) { + $values = current($values); + } else { + $this->prepareMultiFilter($primary, $values); + } - $this->filter([$primary => array_unique($values, SORT_REGULAR)]); + $this->filter([$primary => $values]); $this->select[] = $primary; } diff --git a/src/Queries/UserQuery.php b/src/Queries/UserQuery.php index e3274b0..a453015 100644 --- a/src/Queries/UserQuery.php +++ b/src/Queries/UserQuery.php @@ -222,4 +222,9 @@ protected function normalizeUfSelect() { return preg_grep('/^(UF_+)/', $this->select); } + + protected function prepareMultiFilter(&$key, &$value) + { + $value = join(' | ', $value); + } } diff --git a/tests/RelationTest.php b/tests/RelationTest.php index 2b4eb33..359617c 100644 --- a/tests/RelationTest.php +++ b/tests/RelationTest.php @@ -139,7 +139,7 @@ public function testOne() $bxObject = m::mock('obj'); - $bxObject->shouldReceive('GetList')->with(m::any(), ['IBLOCK_ID' => TestElement2::IBLOCK_ID, 'PROPERTY_ELEMENT' => [1]], m::any(), ['nPageSize' => 1], m::any())->once()->andReturn(m::self()); + $bxObject->shouldReceive('GetList')->with(m::any(), ['IBLOCK_ID' => TestElement2::IBLOCK_ID, 'PROPERTY_ELEMENT' => 1], m::any(), ['nPageSize' => 1], m::any())->once()->andReturn(m::self()); $brandField = [ 'ID' => 1, 'NAME' => 'Название', @@ -155,4 +155,4 @@ public function testOne() // Проверка, что не выполняются дополнительные запросы $product->element; } -} \ No newline at end of file +}