DDC-1150: BasicEntityPersister::expandParameters does not check assiciation mapping when expanding parameters #1445

Closed
opened 2026-01-22 13:14:38 +01:00 by admin · 7 comments
Owner

Originally created by @doctrinebot on GitHub (May 13, 2011).

Originally assigned to: @guilhermeblanco on GitHub.

Jira issue originally created by user realmfoo:

If you try to find entities, filtering them by field with association mapping (ManyToOne) and use an array as a filter argument it will not work:

    $em->getRepository('EntityBundle:Entity')->findBy(array('child' => array(1,2,3)));
    8 Array to string conversion vendor/doctrine-dbal/lib/Doctrine/DBAL/Connection.php 595

I fixed method BasicEntityPersister::expandParameters:


Index: ../vendor/doctrine/lib/Doctrine/ORM/Persisters/BasicEntityPersister.php
===================================================================
@@ -1300,6 <ins>1300,9 @@
             if (isset($this->_class->fieldMappings[$field])) {
                 $type = Type::getType($this->_class->fieldMappings[$field]['type'])->getBindingType();
             }
</ins>            if (isset($this->_class->associationMappings[$field])) {
<ins>                $type = $this->_class->associationMappings[$field]['type'];
</ins>            }
             if (is_array($value)) {
                 $type += Connection::ARRAY*PARAM*OFFSET;
             }
Originally created by @doctrinebot on GitHub (May 13, 2011). Originally assigned to: @guilhermeblanco on GitHub. Jira issue originally created by user realmfoo: If you try to find entities, filtering them by field with association mapping (ManyToOne) and use an array as a filter argument it will not work: ``` $em->getRepository('EntityBundle:Entity')->findBy(array('child' => array(1,2,3))); 8 Array to string conversion vendor/doctrine-dbal/lib/Doctrine/DBAL/Connection.php 595 ``` I fixed method BasicEntityPersister::expandParameters: ``` Index: ../vendor/doctrine/lib/Doctrine/ORM/Persisters/BasicEntityPersister.php =================================================================== @@ -1300,6 <ins>1300,9 @@ if (isset($this->_class->fieldMappings[$field])) { $type = Type::getType($this->_class->fieldMappings[$field]['type'])->getBindingType(); } </ins> if (isset($this->_class->associationMappings[$field])) { <ins> $type = $this->_class->associationMappings[$field]['type']; </ins> } if (is_array($value)) { $type += Connection::ARRAY*PARAM*OFFSET; } ```
admin added the Bug label 2026-01-22 13:14:38 +01:00
admin closed this issue 2026-01-22 13:14:40 +01:00
Author
Owner

@doctrinebot commented on GitHub (Jun 5, 2011):

Comment created by @beberlei:

What is $this->_class->associationMappings[$field]['type'] supposed to be? This key does not exist

@doctrinebot commented on GitHub (Jun 5, 2011): Comment created by @beberlei: What is $this->_class->associationMappings[$field]['type'] supposed to be? This key does not exist
Author
Owner

@doctrinebot commented on GitHub (Jun 5, 2011):

Comment created by realmfoo:

The key exists when ToMany association is used. $field['type'] is a real Doctrine's type of the field, because fieldMappings contains entity type of association.

Checking of this key in Doctrine itself:
https://github.com/doctrine/doctrine2/blob/master/lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php#L386

@doctrinebot commented on GitHub (Jun 5, 2011): Comment created by realmfoo: The key exists when ToMany association is used. $field['type'] is a real Doctrine's type of the field, because fieldMappings contains entity type of association. Checking of this key in Doctrine itself: https://github.com/doctrine/doctrine2/blob/master/lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php#L386
Author
Owner

@doctrinebot commented on GitHub (Jun 11, 2011):

Comment created by @beberlei:

Yes buts its the type of the association, MANY_TO_ONE ,ONE_TO_MANY, etc, etc..The type of the associated column is not really known.

@doctrinebot commented on GitHub (Jun 11, 2011): Comment created by @beberlei: Yes buts its the type of the association, MANY_TO_ONE ,ONE_TO_MANY, etc, etc..The type of the associated column is not really known.
Author
Owner

@doctrinebot commented on GitHub (Jun 14, 2011):

Comment created by realmfoo:

Heh, I was lucky, thanks for pointing it out :)

In any case we still can find this type by the target class. May be it will be a good to cache it in the associationMappings array (by functions like _validateAndCompleteOneToOneMapping)?

@doctrinebot commented on GitHub (Jun 14, 2011): Comment created by realmfoo: Heh, I was lucky, thanks for pointing it out :) In any case we still can find this type by the target class. May be it will be a good to cache it in the associationMappings array (by functions like _validateAndCompleteOneToOneMapping)?
Author
Owner

@doctrinebot commented on GitHub (Jun 14, 2011):

Comment created by @beberlei:

At that point you still don't have the information since its saved on the related association and we don't access it at this point (otherwise you get a riffling effect and everything is in memory). We could just assume it is PDO::PARAM_STR.

@doctrinebot commented on GitHub (Jun 14, 2011): Comment created by @beberlei: At that point you still don't have the information since its saved on the related association and we don't access it at this point (otherwise you get a riffling effect and everything is in memory). We could just assume it is PDO::PARAM_STR.
Author
Owner

@doctrinebot commented on GitHub (Aug 14, 2011):

Comment created by @guilhermeblanco:

This issue was fixed in 63a2f02f4d

Thanks for the report and attempting to fix the issue. =)

@doctrinebot commented on GitHub (Aug 14, 2011): Comment created by @guilhermeblanco: This issue was fixed in https://github.com/doctrine/doctrine2/commit/63a2f02f4ddea1ab9191b0e4acfd1d790d2247c7 Thanks for the report and attempting to fix the issue. =)
Author
Owner

@doctrinebot commented on GitHub (Aug 14, 2011):

Issue was closed with resolution "Fixed"

@doctrinebot commented on GitHub (Aug 14, 2011): Issue was closed with resolution "Fixed"
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#1445