[DDC-1150] BasicEntityPersister::expandParameters does not check assiciation mapping when expanding parameters Created: 13/May/11  Updated: 14/Aug/11  Resolved: 14/Aug/11

Status: Resolved
Project: Doctrine 2 - ORM
Component/s: ORM
Affects Version/s: None
Fix Version/s: 2.2
Security Level: All

Type: Bug Priority: Major
Reporter: Konstantin Assignee: Guilherme Blanco
Resolution: Fixed Votes: 0
Labels: None


 Description   

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 +1300,9 @@
             if (isset($this->_class->fieldMappings[$field])) {
                 $type = Type::getType($this->_class->fieldMappings[$field]['type'])->getBindingType();
             }
+            if (isset($this->_class->associationMappings[$field])) {
+                $type = $this->_class->associationMappings[$field]['type'];
+            }
             if (is_array($value)) {
                 $type += Connection::ARRAY_PARAM_OFFSET;
             }


 Comments   
Comment by Benjamin Eberlei [ 05/Jun/11 ]

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

Comment by Konstantin [ 05/Jun/11 ]

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

Comment by Benjamin Eberlei [ 11/Jun/11 ]

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.

Comment by Konstantin [ 14/Jun/11 ]

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)?

Comment by Benjamin Eberlei [ 14/Jun/11 ]

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.

Comment by Guilherme Blanco [ 14/Aug/11 ]

This issue was fixed in https://github.com/doctrine/doctrine2/commit/63a2f02f4ddea1ab9191b0e4acfd1d790d2247c7

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

Generated at Mon Jul 28 22:47:07 UTC 2014 using JIRA 6.2.3#6260-sha1:63ef1d6dac3f4f4d7db4c1effd405ba38ccdc558.