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

Closed
opened 2026-01-22 12:50:24 +01:00 by admin · 8 comments
Owner

Originally created by @doctrinebot on GitHub (Jun 11, 2010).

Originally assigned to: @beberlei on GitHub.

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.

Originally created by @doctrinebot on GitHub (Jun 11, 2010). Originally assigned to: @beberlei on GitHub. 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.
admin added the Bug label 2026-01-22 12:50:24 +01:00
admin closed this issue 2026-01-22 12:50:24 +01:00
Author
Owner

@doctrinebot commented on GitHub (Aug 8, 2010):

Comment created by @beberlei:

Fixed in master

@doctrinebot commented on GitHub (Aug 8, 2010): Comment created by @beberlei: Fixed in master
Author
Owner

@doctrinebot commented on GitHub (Aug 8, 2010):

Issue was closed with resolution "Fixed"

@doctrinebot commented on GitHub (Aug 8, 2010): Issue was closed with resolution "Fixed"
Author
Owner

@doctrinebot commented on GitHub (Aug 17, 2010):

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 commented on GitHub (Aug 17, 2010): 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?
Author
Owner

@doctrinebot commented on GitHub (Aug 17, 2010):

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 commented on GitHub (Aug 17, 2010): 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.
Author
Owner

@doctrinebot commented on GitHub (Aug 17, 2010):

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 commented on GitHub (Aug 17, 2010): 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?
Author
Owner

@doctrinebot commented on GitHub (Sep 28, 2010):

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

@doctrinebot commented on GitHub (Sep 28, 2010): 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.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.
Author
Owner

@doctrinebot commented on GitHub (Sep 28, 2010):

Comment created by @beberlei:

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

@doctrinebot commented on GitHub (Sep 28, 2010): Comment created by @beberlei: Eager doesnt mean it does a Join, it only means the query is executed directly
Author
Owner

@doctrinebot commented on GitHub (Sep 28, 2010):

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() ?

@doctrinebot commented on GitHub (Sep 28, 2010): 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() ?
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#786