Doctrine 2 - ORM
  1. Doctrine 2 - ORM
  2. DDC-633

fetch="EAGER" is not loading one to one associations

    Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Critical Critical
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 2.0-BETA4
    • Component/s: ORM
    • Security Level: All
    • Labels:
      None

      Description

      <?php
      namespace vo;
      
      /**
       * @Entity
       */
      
      class Appointment {
      	
          /** @Id @Column(type="integer") @GeneratedValue(strategy="IDENTITY") */
          public $id;
      	
      	/**
           * @OneToOne(targetEntity="Patient", inversedBy="appointment", fetch="EAGER")
      	 * @JoinColumn(name="patient_id", referencedColumnName="id")
           */
      	public $patient;
      	
      }
      

      When doing a findAll() on appointments, $patient is being created as a proxy even though fetch is EAGER.

        Activity

        Dave Keen created issue -
        Dave Keen made changes -
        Field Original Value New Value
        Description [code]
        <?php
        namespace vo;

        /**
         * @Entity
         */

        class Appointment {

            /** @Id @Column(type="integer") @GeneratedValue(strategy="IDENTITY") */
            public $id;

        /**
             * @OneToOne(targetEntity="Patient", inversedBy="appointment", fetch="EAGER")
        * @JoinColumn(name="patient_id", referencedColumnName="id")
             */
        public $patient;

        }
        [code]

        When doing a findAll() on appointments, $patient is being created as a proxy even though fetch is EAGER.
        {code}
        <?php
        namespace vo;

        /**
         * @Entity
         */

        class Appointment {

            /** @Id @Column(type="integer") @GeneratedValue(strategy="IDENTITY") */
            public $id;

        /**
             * @OneToOne(targetEntity="Patient", inversedBy="appointment", fetch="EAGER")
        * @JoinColumn(name="patient_id", referencedColumnName="id")
             */
        public $patient;

        }
        {code}

        When doing a findAll() on appointments, $patient is being created as a proxy even though fetch is EAGER.
        Roman S. Borschel made changes -
        Fix Version/s 2.0-BETA4 [ 10072 ]
        Roman S. Borschel made changes -
        Priority Major [ 3 ] Critical [ 2 ]
        Roman S. Borschel made changes -
        Assignee Roman S. Borschel [ romanb ] Benjamin Eberlei [ beberlei ]
        Hide
        Benjamin Eberlei added a comment -

        Fixed in master

        Show
        Benjamin Eberlei added a comment - Fixed in master
        Benjamin Eberlei made changes -
        Status Open [ 1 ] Resolved [ 5 ]
        Resolution Fixed [ 1 ]
        Hide
        Michael Moravec added a comment -

        What is an advantage of this solution (in master) if it is loaded in the same way as when fetched lazily? Maybe it'd be better to use INNER JOIN instead, at least for OneToOne and save one or more (probably unnecessary) SQL queries?

        Show
        Michael Moravec added a comment - What is an advantage of this solution (in master) if it is loaded in the same way as when fetched lazily? Maybe it'd be better to use INNER JOIN instead, at least for OneToOne and save one or more (probably unnecessary) SQL queries?
        Hide
        Benjamin Eberlei added a comment -

        There is none (yet), it may be a future enhancement, however we dont know this yet. fetch=EAGER is not so useful at the moment.

        Show
        Benjamin Eberlei added a comment - There is none (yet), it may be a future enhancement, however we dont know this yet. fetch=EAGER is not so useful at the moment.
        Hide
        Michael Moravec added a comment -

        I think that fetch=EAGER should behave like this DQL:
        SELECT a, b FROM foo a JOIN a.bar b
        This query will use INNER JOIN to load "a.bar" association, but fetch=EAGER won't.

        Should I open a new issue for this?

        Show
        Michael Moravec added a comment - I think that fetch=EAGER should behave like this DQL: SELECT a, b FROM foo a JOIN a.bar b This query will use INNER JOIN to load "a.bar" association, but fetch=EAGER won't. Should I open a new issue for this?
        Hide
        Eduard Kracmar added a comment - - edited

        fetch=EAGER still is not working as I think it should.

        class Project {

        /**

        • @id
        • @column(type="integer")
        • @generatedValue(strategy="SEQUENCE")
          */
          private $id;
          /**
        • @manyToOne(targetEntity="Client", inversedBy="projects", fetch="EAGER")
        • @joinColumn(name="id_client", referencedColumnName="id",nullable=false, onDelete="cascade")
          */
          private $client;

        but after

        $this->getEntityManager()>find('\Entities\Project', $this>project);

        2 doctrine queries are executed:

        SELECT t0.id AS id1, t0.name AS name2, t0.paths AS paths3, t0.modified AS modified4, t0.created AS
        created5, t0.has_running_tasks AS has_running_tasks6, t0.tasksCount AS taskscount7, t0.productsCount
        AS productscount8, t0.id_client AS id_client9
        FROM projects t0
        WHERE t0.id = ?

        SELECT t0.id AS id1, t0.name AS name2, t0.modified AS modified3, t0.created AS created4
        FROM clients t0
        WHERE t0.id = ?

        And it should be one query with inner join to clients.

        Show
        Eduard Kracmar added a comment - - edited fetch=EAGER still is not working as I think it should. class Project { /** @id @column(type="integer") @generatedValue(strategy="SEQUENCE") */ private $id; /** @manyToOne(targetEntity="Client", inversedBy="projects", fetch="EAGER") @joinColumn(name="id_client", referencedColumnName="id",nullable=false, onDelete="cascade") */ private $client; but after $this->getEntityManager() >find('\Entities\Project', $this >project); 2 doctrine queries are executed: SELECT t0.id AS id1, t0.name AS name2, t0.paths AS paths3, t0.modified AS modified4, t0.created AS created5, t0.has_running_tasks AS has_running_tasks6, t0.tasksCount AS taskscount7, t0.productsCount AS productscount8, t0.id_client AS id_client9 FROM projects t0 WHERE t0.id = ? SELECT t0.id AS id1, t0.name AS name2, t0.modified AS modified3, t0.created AS created4 FROM clients t0 WHERE t0.id = ? And it should be one query with inner join to clients.
        Hide
        Benjamin Eberlei added a comment -

        Eager doesnt mean it does a Join, it only means the query is executed directly

        Show
        Benjamin Eberlei added a comment - Eager doesnt mean it does a Join, it only means the query is executed directly
        Hide
        Eduard Kracmar added a comment -

        I see. And how can be achieved that product and client will be queried at once, and not only when I request product->getClient() ?

        Show
        Eduard Kracmar added a comment - I see. And how can be achieved that product and client will be queried at once, and not only when I request product->getClient() ?
        Benjamin Eberlei made changes -
        Workflow jira [ 11477 ] jira-feedback [ 14457 ]
        Benjamin Eberlei made changes -
        Workflow jira-feedback [ 14457 ] jira-feedback2 [ 16321 ]
        Benjamin Eberlei made changes -
        Workflow jira-feedback2 [ 16321 ] jira-feedback3 [ 18574 ]

        This list may be incomplete, as errors occurred whilst retrieving source from linked applications:

        • Request to http://www.doctrine-project.org/fisheye/ failed: Error in remote call to 'FishEye 0 (http://www.doctrine-project.org/fisheye/)' (http://www.doctrine-project.org/fisheye) [AbstractRestCommand{path='/rest-service-fe/search-v1/crossRepositoryQuery', params={query=DDC-633, expand=changesets[0:20].revisions[0:29],reviews}, methodType=GET}] : Received status code 503 (Service Temporarily Unavailable)

          People

          • Assignee:
            Benjamin Eberlei
            Reporter:
            Dave Keen
          • Votes:
            1 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: