Doctrine 2 - ORM
  1. Doctrine 2 - ORM
  2. DDC-1239

Using a repository with composite keys generates invalid SQL

    Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 2.1
    • Fix Version/s: 2.1
    • Component/s: None
    • Security Level: All
    • Labels:
      None
    • Environment:
      Ubuntu 11.04 (standard LAMP stack), PHP 5.3, MySQL 5.x, Apache 2

      Description

      Invalid SQL is generated when using composite keys along with Repository methods (fineOneBy, etc). Everything works properly when using createQuery() to generate DQL manually.

      Working:
      $q = $this->_em
      ->createQuery(
      "SELECT c,c2,g FROM Entity\OAuth\Consumer c LEFT JOIN c.group g LEFT JOIN c.clinic c2 WHERE c.key = '{$consumer_key}'");
      $this->_consumer = $q->getSingleResult();

      Invalid:
      $this->_consumer = $this->_em->getRepository('Entity\OAuth\Consumer')
      ->findOneBy(array('key' => $consumer_key));

      Generated SQL for "invalid" method:
      SELECT ... FROM oauth_consumer t0 LEFT JOIN groop t10 ON t0.groupId = t10.id LEFT JOIN company t17 ON t0.companyId = t17.id LEFT JOIN clinic t28 ON t0.dsid = t28.dsid t0.rid = t28.rid LEFT JOIN user t50 ON t0.userId = t50.id WHERE t0.`key` = ?

      Notice the missing AND in the query above. I've attached the entities in question.

      1. Clinic.php
        2 kB
        Kyle Spraggs
      2. Consumer.php
        1 kB
        Kyle Spraggs

        Activity

        Hide
        Benjamin Eberlei added a comment -

        Fixed

        Show
        Benjamin Eberlei added a comment - Fixed

          People

          • Assignee:
            Benjamin Eberlei
            Reporter:
            Kyle Spraggs
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: