[DDC-633] fetch="EAGER" is not loading one to one associations Created: 11/Jun/10  Updated: 28/Sep/10  Resolved: 08/Aug/10

Status: Resolved
Project: Doctrine 2 - ORM
Component/s: ORM
Affects Version/s: None
Fix Version/s: 2.0-BETA4
Security Level: All

Type: Bug Priority: Critical
Reporter: Dave Keen Assignee: Benjamin Eberlei
Resolution: Fixed Votes: 1
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.



 Comments   
Comment by Benjamin Eberlei [ 08/Aug/10 ]

Fixed in master

Comment by Michael Moravec [ 17/Aug/10 ]

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?

Comment by Benjamin Eberlei [ 17/Aug/10 ]

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.

Comment by Michael Moravec [ 17/Aug/10 ]

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?

Comment by Eduard Kracmar [ 28/Sep/10 ]

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.

Comment by Benjamin Eberlei [ 28/Sep/10 ]

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

Comment by Eduard Kracmar [ 28/Sep/10 ]

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

Generated at Tue Jul 29 10:43:09 UTC 2014 using JIRA 6.2.3#6260-sha1:63ef1d6dac3f4f4d7db4c1effd405ba38ccdc558.