Doctrine 2 - ORM
  1. Doctrine 2 - ORM
  2. DDC-1999

Lazy loading doesn't get the field type when generating sql

    Details

    • Type: Bug Bug
    • Status: Open
    • Priority: Major Major
    • Resolution: Unresolved
    • Affects Version/s: None
    • Fix Version/s: None
    • Component/s: None
    • Security Level: All
    • Labels:
      None

      Description

      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
                  default:
      
                  	$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'];
      							}
      
      							break;
      						}
      	            	}
                  	}
      //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 .

        Activity

        Hide
        Benjamin Eberlei added a comment -

        Fabio B. Silva Guilherme Blanco do we have a current best practice/policy regarding casting of join column types? There are some issues regarding it, this is another one.

        Show
        Benjamin Eberlei added a comment - Fabio B. Silva Guilherme Blanco do we have a current best practice/policy regarding casting of join column types? There are some issues regarding it, this is another one.
        Hide
        Guilherme Blanco added a comment -

        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.

        Show
        Guilherme Blanco added a comment - 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.

          People

          • Assignee:
            Benjamin Eberlei
            Reporter:
            victor Velkov
          • Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

            • Created:
              Updated: