Skip to content

Commit

Permalink
Merge pull request #6 from vemaeg/bugfix/duplicate-columns-with-diffe…
Browse files Browse the repository at this point in the history
…rent-cases

Not exactly sure, what this fix was used for. It filters out duplicat…
  • Loading branch information
thirsch authored Dec 15, 2022
2 parents 32d4d6d + dcf4b71 commit 81b3c8b
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions lib/Doctrine/Table.php
Original file line number Diff line number Diff line change
Expand Up @@ -2774,13 +2774,16 @@ public function buildFindByWhere($fieldName)
}
$fields = array_merge($fields, $ucfirstFields);

// Remove duplicate entries.
$fields = array_unique($fields);

// Sort field names by length - smallest first
// and then reverse so that largest is first
usort($fields, array($this, 'isGreaterThan'));
$fields = array_reverse(array_unique($fields));

// Identify fields and operators
preg_match_all('/(' . implode('|', $fields) . ')(Or|And)?/', $fieldName, $matches);
preg_match_all('/((?i)' . implode('|', $fields) . ')(Or|And)?/', $fieldName, $matches);
$fieldsFound = $matches[1];
$operatorFound = $matches[2];
foreach ($operatorFound as &$v) {
Expand All @@ -2789,7 +2792,7 @@ public function buildFindByWhere($fieldName)

// Check if $fieldName has unidentified parts left
if (strlen(implode('', $fieldsFound) . implode('', $operatorFound)) !== strlen($fieldName)) {
$expression = preg_replace('/(' . implode('|', $fields) . ')(Or|And)?/', '($1)$2', $fieldName);
$expression = preg_replace('/((?i)' . implode('|', $fields) . ')(Or|And)?/', '($1)$2', $fieldName);
throw new Doctrine_Table_Exception('Invalid expression found: ' . $expression);
}

Expand Down

0 comments on commit 81b3c8b

Please sign in to comment.