Skip to content


DDC-1999: Lazy loading doesn't get the field type when generating sql #2674

doctrinebot opened this Issue · 2 comments

2 participants


Jira issue originally created by user vigor_bg:

When calling with lazy loading the Sql generated doesn't convert the parameters according to their types. After debugging the problem I found that the problem is in the getType($field, $value) function in the BasicEntityPersister as it is it will never be able to return the filed type when called for lazy loading for oneToMany or ManyToMany. I put a quick fix for my self

 private function getType($field, $value)

        switch (true) {
           //here we have original code

                $type = null;
               // my fix starts here
                $fieldParts = explode('.', $field);
                if (count($fieldParts > 1)) {
                    foreach ($this->_class->associationMappings as $mapping) {
                        if (isset($mapping['joinColumnFieldNames'][$fieldParts[1]])) {
                            $targetClass  = $this->_em->getClassMetadata($mapping['targetEntity']);

                            if (isset($targetClass->fieldNames[$fieldParts[1]])) {
                                $type = $targetClass->fieldMappings[$targetClass->fieldNames[$fieldParts[1]]]['type'];

//my fix end here

       //here we have original code

        return $type;

i have only added that check in the default case of the switch. I am not sure if that is the most elegant way. I hope that helps and that it will be fixed soon. Thanks for the great work :).


Comment created by @beberlei:

[fabio.bat.silva] [guilhermeblanco] do we have a current best practice/policy regarding casting of join column types? There are some issues regarding it, this is another one.


Comment created by @guilhermeblanco:

We avoid the manual breakdown of path expressions.
Also, in BasicEntityPersister it is done behind the scenes and can get into weird scenarios. Personally speaking, I don't see how we can easily fix this issue.

@beberlei beberlei was assigned by doctrinebot
@doctrinebot doctrinebot added the Bug label
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.