Doctrine 2 - ORM
  1. Doctrine 2 - ORM
  2. DDC-1376

Foreign key not available to order when using findBy()

    Details

    • Type: Improvement Improvement
    • Status: Resolved
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 2.1.1
    • Fix Version/s: 2.4
    • Component/s: ORM
    • Security Level: All
    • Labels:
      None

      Description

      <?php
      /**
       * Service
       *
       * @Entity(repositoryClass="App_Model_Repository_Si_Service")
       * @Table(name="service")
       */
      class App_Model_Entities_Si_Service
      {
         /**
          * @var int
          *
          * @Id
          * @GeneratedValue(strategy="SEQUENCE")
          * @Column(name="pk", type="integer")
          */
         public $pk;
      
          /**
           * Service parent
           * @var App_Model_Entities_Si_Service
           *
           * @ManyToOne(targetEntity="App_Model_Entities_Si_Service", cascade={"all"}, inversedBy="service")
           * @JoinColumn(name="pk_service", referencedColumnName="pk")
           */
          private $service;
      
         /**
          * Returns an App_Model_Entities_Si_Service that represents the service
          *
          * @return App_Model_Entities_Si_Service
          */
         public function getService(){
            return $this->service;
         }
         /**
          * Set an App_Model_Entities_Si_Service that represents a service
          *
          * @param App_Model_Entities_Si_Service $newService
          */
         public function setService($newService){
            $this->service = $newService;
         }
      }
      
      
      $service = $this->service('Service_Type', true);
      $serviceType = $service->findOneBy(array('code' => 'service'));
              
      $service = $this->service('Service', true);
      $services = $service->findBy(
          array('serviceType' => $serviceType->getPk()),
          array('service' => 'ASC')
      );
      

      Using orderBy parameter of EntityRepository::findBy() with Foreign Key do not work.
      An Unrecognized field error occured.

      Of course, i can use DQL but i think this function should work with mapping.

      Thank you in advance

        Activity

        Hide
        Benjamin Eberlei added a comment -

        Not a bug

        Show
        Benjamin Eberlei added a comment - Not a bug
        Show
        Fabio B. Silva added a comment - Fixed : https://github.com/doctrine/doctrine2/commit/b30b06852bc4eacf8bbbed472e1d6ec21310ec0a

          People

          • Assignee:
            Fabio B. Silva
            Reporter:
            Presteus
          • Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: