DDC-633: fetch="EAGER" is not loading one to one associations #5143

Closed
doctrinebot opened this Issue Jun 11, 2010 · 8 comments

2 participants

@doctrinebot

Jira issue originally created by user ccapndave:

<?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.

@doctrinebot

Comment created by @beberlei:

Fixed in master

@doctrinebot

Issue was closed with resolution "Fixed"

@doctrinebot

Comment created by majkl578:

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?

@doctrinebot

Comment created by @beberlei:

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.

@doctrinebot

Comment created by majkl578:

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?

@doctrinebot

Comment created by edke:

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.hasrunning_tasks AS has_runningtasks6, t0.tasksCount AS taskscount7, t0.productsCount
AS productscount8, t0.idclient AS idclient9
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.

@doctrinebot

Comment created by @beberlei:

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

@doctrinebot

Comment created by edke:

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

@beberlei beberlei was assigned by doctrinebot Dec 6, 2015
@doctrinebot doctrinebot added this to the 2.0-BETA4 milestone Dec 6, 2015
@doctrinebot doctrinebot closed this Dec 6, 2015
@doctrinebot doctrinebot added the Bug label Dec 7, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment