Skip to content

Commit f0443d5

Browse files
committed
feat: dedupe where clauses
1 parent ff9118d commit f0443d5

File tree

3 files changed

+47
-31
lines changed

3 files changed

+47
-31
lines changed

.vscode/settings.json

Lines changed: 30 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,30 @@
1-
{
2-
"files.trimTrailingWhitespace": true,
3-
"intelephense.completion.insertUseDeclaration": false,
4-
"intelephense.environment.shortOpenTag": false,
5-
"intelephense.format.braces": "per",
6-
"intelephense.phpdoc.useFullyQualifiedNames": true,
7-
"php.suggest.basic": false,
8-
"prettier.enable": false,
9-
"files.exclude": {
10-
"composer.lock": true,
11-
".phpunit.result.cache": true
12-
},
13-
"search.exclude": {},
14-
"[php]": {
15-
"editor.formatOnSave": true,
16-
"editor.tabSize": 4,
17-
"editor.detectIndentation": false,
18-
"editor.insertSpaces": true,
19-
"editor.defaultFormatter": "Jota0222.multi-formatter",
20-
"multiFormatter.formatterList": [
21-
"bmewburn.vscode-intelephense-client",
22-
"junstyle.php-cs-fixer"
23-
]
24-
},
25-
"editor.codeActionsOnSave": {
26-
"source.fixAll.eslint": "explicit",
27-
"source.organizeImports": "never"
28-
}
29-
}
1+
{
2+
"files.trimTrailingWhitespace": true,
3+
"intelephense.completion.insertUseDeclaration": false,
4+
"intelephense.environment.shortOpenTag": false,
5+
"intelephense.format.braces": "per",
6+
"intelephense.phpdoc.useFullyQualifiedNames": true,
7+
"intelephense.inlayHint.parameterNames": false,
8+
"php.suggest.basic": false,
9+
"prettier.enable": false,
10+
"files.exclude": {
11+
"composer.lock": true,
12+
".phpunit.result.cache": true
13+
},
14+
"search.exclude": {},
15+
"[php]": {
16+
"editor.formatOnSave": true,
17+
"editor.tabSize": 4,
18+
"editor.detectIndentation": false,
19+
"editor.insertSpaces": true,
20+
"editor.defaultFormatter": "Jota0222.multi-formatter",
21+
"multiFormatter.formatterList": [
22+
"bmewburn.vscode-intelephense-client",
23+
"junstyle.php-cs-fixer"
24+
]
25+
},
26+
"editor.codeActionsOnSave": {
27+
"source.fixAll.eslint": "explicit",
28+
"source.organizeImports": "never"
29+
}
30+
}

src/Granada/ORM.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1245,10 +1245,15 @@ protected function _add_condition($type, $fragment, $values = [])
12451245
if (!is_array($values)) {
12461246
$values = [$values];
12471247
}
1248-
array_push($this->$conditions_class_property_name, [
1248+
$filter = [
12491249
self::CONDITION_FRAGMENT => $fragment,
12501250
self::CONDITION_VALUES => $values,
1251-
]);
1251+
];
1252+
if (in_array($filter, $this->$conditions_class_property_name)) {
1253+
// Condition already exists, de-dupe
1254+
return $this;
1255+
}
1256+
array_push($this->$conditions_class_property_name, $filter);
12521257

12531258
return $this;
12541259
}

tests/orm/ORMTest.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,4 +184,14 @@ public function testSaveInsideLoop()
184184
$this->assertEquals($expected, ORM::get_last_query());
185185
}
186186
}
187+
188+
public function testDuplicateFilters()
189+
{
190+
$cars_query = ORM::for_table('car')
191+
->where('name', 'ABC')
192+
->where('name', 'ABC')
193+
->get_select_query();
194+
195+
$this->assertSame("SELECT * FROM `car` WHERE `name` = 'ABC'", $cars_query);
196+
}
187197
}

0 commit comments

Comments
 (0)