Parameter type checking has changed from v2.6.3 #6307

Closed
opened 2026-01-22 15:30:33 +01:00 by admin · 1 comment
Owner

Originally created by @snebes on GitHub (Sep 25, 2019).

BC Break Report

Q A
BC Break yes
Version 2.6.4

Summary

The changes made in #7528 have altered the behavior from what worked in the previous version. Specifically this conditional:

https://github.com/doctrine/orm/pull/7528/files#diff-81228a4fb4c82b292a152dd3e1a40becR435

Previous behavior

Previously, if a Parameter is passed with a defined $type, and that type did not match the actual $value of the parameter, the correct type was inferred from Doctrine. This behavior occurred on this line:

https://github.com/doctrine/orm/pull/7528/files#diff-81228a4fb4c82b292a152dd3e1a40becL407

Current behavior

The behavior has now been changed to blindly accepting the type that was included in the Parameter object as seen here:

https://github.com/doctrine/orm/pull/7528/files#diff-81228a4fb4c82b292a152dd3e1a40becR435

How to reproduce

This change altered the behavior of queries that specifically, but incorrectly, set the type of a parameter. Take for example, a Course and Student relationship with a OneToMany relationship. Consider the following:

<?php

use Doctrine\ORM\Mapping as ORM;

class Course
{
    /**
     * @var Student
     *
     * @ORM\OneToMany(targetEntity="Student", mappedBy="course")
     */
    private $students;
}

class Student
{
    /**
     * @var Course
     *
     * @ORM\ManyToOne(targetEntity="Course", inversedBy="students")
     */
    private $course;
}

// Assume $em and $course are defined.

$queryBuilder = $em->getRepository(Student::class)->createQueryBuilder('student');
$queryBuilder
    ->andWhere('student.course IN(:p_course)')
    ->setParameter('p_course', $course, \Doctrine\DBAL\ParameterType::STRING);
$result = $queryBuilder->getQuery()->getResult();

The generated SQL will be along the lines of:

SELECT * FROM t0 WHERE t0.course_id IN (?)

Where ? would be:

["[object] (Proxies\\__CG__\\App\\Entity\\Course: CompSci 101)"]

Previously, this would resolve to the doctrine-mapped ID field. This now results in 0 entities being returned by getResult, with no clear indication as to why.

The flawed configuration of the setParameter method is the source of the problem, but it was allowed before this version.

Originally created by @snebes on GitHub (Sep 25, 2019). <!-- Before reporting a BC break, please consult the upgrading document to make sure it's not an expected change: https://github.com/doctrine/orm/blob/master/UPGRADE.md --> ### BC Break Report <!-- Fill in the relevant information below to help triage your issue. --> | Q | A |------------ | ------ | BC Break | yes | Version | 2.6.4 #### Summary The changes made in #7528 have altered the behavior from what worked in the previous version. Specifically this conditional: https://github.com/doctrine/orm/pull/7528/files#diff-81228a4fb4c82b292a152dd3e1a40becR435 #### Previous behavior Previously, if a `Parameter` is passed with a defined `$type`, and that type did not match the actual `$value` of the parameter, the correct type was inferred from Doctrine. This behavior occurred on this line: https://github.com/doctrine/orm/pull/7528/files#diff-81228a4fb4c82b292a152dd3e1a40becL407 #### Current behavior The behavior has now been changed to blindly accepting the type that was included in the `Parameter` object as seen here: https://github.com/doctrine/orm/pull/7528/files#diff-81228a4fb4c82b292a152dd3e1a40becR435 #### How to reproduce This change altered the behavior of queries that specifically, but incorrectly, set the type of a parameter. Take for example, a Course and Student relationship with a OneToMany relationship. Consider the following: ``` <?php use Doctrine\ORM\Mapping as ORM; class Course { /** * @var Student * * @ORM\OneToMany(targetEntity="Student", mappedBy="course") */ private $students; } class Student { /** * @var Course * * @ORM\ManyToOne(targetEntity="Course", inversedBy="students") */ private $course; } // Assume $em and $course are defined. $queryBuilder = $em->getRepository(Student::class)->createQueryBuilder('student'); $queryBuilder ->andWhere('student.course IN(:p_course)') ->setParameter('p_course', $course, \Doctrine\DBAL\ParameterType::STRING); $result = $queryBuilder->getQuery()->getResult(); ``` The generated SQL will be along the lines of: ``` SELECT * FROM t0 WHERE t0.course_id IN (?) ``` Where ? would be: ``` ["[object] (Proxies\\__CG__\\App\\Entity\\Course: CompSci 101)"] ``` Previously, this would resolve to the doctrine-mapped ID field. This now results in 0 entities being returned by `getResult`, with no clear indication as to why. The flawed configuration of the `setParameter` method is the source of the problem, but it was allowed before this version.
admin closed this issue 2026-01-22 15:30:33 +01:00
Author
Owner

@snebes commented on GitHub (Sep 25, 2019):

And I should have checked first, this is a dupe of #7827

@snebes commented on GitHub (Sep 25, 2019): And I should have checked first, this is a dupe of #7827
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#6307