ManyToManyPersister::loadCriteria IN operator bad translation #6279

Open
opened 2026-01-22 15:30:02 +01:00 by admin · 2 comments
Owner

Originally created by @bednic on GitHub (Aug 9, 2019).

Originally assigned to: @bednic on GitHub.

Bug Report

Q A
BC Break no
Version 2.6.3

Summary

Current behavior

If you use Criteria::exp()->in() on relation collection, in this case ManyToMany, the query built in method ::loadCriteria translate are wrong.

        foreach ($parameters as $parameter) {
            [$name, $value, $operator] = $parameter;

            $field          = $this->quoteStrategy->getColumnName($name, $targetClass, $this->platform);
            $whereClauses[] = sprintf('te.%s %s ?', $field, $operator);
            $params[]       = $value;
        }

are translated to this

 WHERE t.region_id = ? AND te.status IN ?' with params [1, ["finished","error"]]

but should end up like this

WHERE t.region_id = ? AND te.status IN (?,?)' with params [1, ["finished","error"]]

How to reproduce

Expected behavior

It should be enough if someone add something like this:

            if (is_array($value)) {
                $whereClauses[] = sprintf('te.%s IN (' . str_repeat('?,', count($value) - 1) . '?)', $field);
                $params         = array_merge($params, $value);
            }
            else {
                $whereClauses[] = sprintf('te.%s %s ?', $field, $operator);
                $params[]       = $value;
            }
Originally created by @bednic on GitHub (Aug 9, 2019). Originally assigned to: @bednic on GitHub. ### Bug Report <!-- Fill in the relevant information below to help triage your issue. --> | Q | A |------------ | ------ | BC Break | no | Version | 2.6.3 #### Summary #### Current behavior If you use Criteria::exp()->in() on relation collection, in this case ManyToMany, the query built in method ::loadCriteria translate are wrong. ``` foreach ($parameters as $parameter) { [$name, $value, $operator] = $parameter; $field = $this->quoteStrategy->getColumnName($name, $targetClass, $this->platform); $whereClauses[] = sprintf('te.%s %s ?', $field, $operator); $params[] = $value; } ``` are translated to this ``` WHERE t.region_id = ? AND te.status IN ?' with params [1, ["finished","error"]] ``` but should end up like this ``` WHERE t.region_id = ? AND te.status IN (?,?)' with params [1, ["finished","error"]] ``` #### How to reproduce #### Expected behavior It should be enough if someone add something like this: ``` if (is_array($value)) { $whereClauses[] = sprintf('te.%s IN (' . str_repeat('?,', count($value) - 1) . '?)', $field); $params = array_merge($params, $value); } else { $whereClauses[] = sprintf('te.%s %s ?', $field, $operator); $params[] = $value; } ```
admin added the BugMissing Tests labels 2026-01-22 15:30:02 +01:00
Author
Owner

@bednic commented on GitHub (Aug 10, 2019):

After deep inspect I suppose whole ManyToManyPersister should be reworked. It works with database but missing all SQL translation techniks from BasicEntityPersister, so most of advanced queries are invalid. For example LIKE is translated to CONTIANS, IN don't expand parameters before query execution. There is a lot of work 😞

@bednic commented on GitHub (Aug 10, 2019): After deep inspect I suppose whole ManyToManyPersister should be reworked. It works with database but missing all SQL translation techniks from BasicEntityPersister, so most of advanced queries are invalid. For example LIKE is translated to CONTIANS, IN don't expand parameters before query execution. There is a lot of work 😞
Author
Owner

@lcobucci commented on GitHub (Oct 2, 2019):

@bednic would you be able to send us a failing functional test case that reproduces this issue (targetting 2.6)? It would help us a lot to find a way to fix things 👍

@lcobucci commented on GitHub (Oct 2, 2019): @bednic would you be able to send us a failing functional test case that reproduces this issue (targetting `2.6`)? It would help us a lot to find a way to fix things :+1:
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#6279