doctrine 2 LAZY one-to-one fetching of association no working in reverse side #6035

Closed
opened 2026-01-22 15:25:10 +01:00 by admin · 2 comments
Owner

Originally created by @INHack20 on GitHub (Aug 14, 2018).

Originally assigned to: @Ocramius on GitHub.

Bug Report

When performing a relation of the reverse side and obtaining the entity from the database, the query of the elements declared in the one-to-one relationship is executed.

Option EXTRA_LAZY nor LAZY does not work.

Q A
BC Break yes/no
Versions
doctrine/annotations v1.4.0 Docblock Annotations Parser
doctrine/cache v1.6.2 Caching library offering an object-oriented API for many cache backends
doctrine/collections v1.4.0 Collections Abstraction library
doctrine/common v2.7.3 Common Library for Doctrine projects
doctrine/data-fixtures v1.2.2 Data Fixtures for all Doctrine Object Managers
doctrine/dbal v2.5.13 Database Abstraction Layer
doctrine/doctrine-bundle 1.9.1 Symfony DoctrineBundle
doctrine/doctrine-cache-bundle 1.3.0 Symfony Bundle for Doctrine Cache
doctrine/doctrine-fixtures-bundle v2.4.0 Symfony DoctrineFixturesBundle
doctrine/doctrine-migrations-bundle v1.3.1 Symfony DoctrineMigrationsBundle

Declare:

/**
* @var Balance
* @ORM\OneToOne(targetEntity="Balance",mappedBy="digitalAccount",fetch="LAZY")
*/
protected $balance;

and

/**
 * @var DigitalAccount
 * @ORM\OneToOne(targetEntity="DigitalAccount",inversedBy="balance",fetch="LAZY")
 * @ORM\JoinColumn(nullable=false)
 */
protected $digitalAccount;

Summary

When you obtain DigitalAccount entity, you automatically get $ balance automatically without calling getBalance ()

Current behavior

How to reproduce

Declare one-to-one in reverse side is the error.

Expected behavior

No additional query to call the getBalance () method as it works on the owner side.

Originally created by @INHack20 on GitHub (Aug 14, 2018). Originally assigned to: @Ocramius on GitHub. ### Bug Report When performing a relation of the reverse side and obtaining the entity from the database, the query of the elements declared in the one-to-one relationship is executed. Option EXTRA_LAZY nor LAZY does not work. | Q | A |------------ | ------ | BC Break | yes/no | Versions doctrine/annotations v1.4.0 Docblock Annotations Parser doctrine/cache v1.6.2 Caching library offering an object-oriented API for many cache backends doctrine/collections v1.4.0 Collections Abstraction library doctrine/common v2.7.3 Common Library for Doctrine projects doctrine/data-fixtures v1.2.2 Data Fixtures for all Doctrine Object Managers doctrine/dbal v2.5.13 Database Abstraction Layer doctrine/doctrine-bundle 1.9.1 Symfony DoctrineBundle doctrine/doctrine-cache-bundle 1.3.0 Symfony Bundle for Doctrine Cache doctrine/doctrine-fixtures-bundle v2.4.0 Symfony DoctrineFixturesBundle doctrine/doctrine-migrations-bundle v1.3.1 Symfony DoctrineMigrationsBundle Declare: /** * @var Balance * @ORM\OneToOne(targetEntity="Balance",mappedBy="digitalAccount",fetch="LAZY") */ protected $balance; and /** * @var DigitalAccount * @ORM\OneToOne(targetEntity="DigitalAccount",inversedBy="balance",fetch="LAZY") * @ORM\JoinColumn(nullable=false) */ protected $digitalAccount; #### Summary When you obtain DigitalAccount entity, you automatically get $ balance automatically without calling getBalance () #### Current behavior <!-- What is the current (buggy) behavior? --> #### How to reproduce Declare one-to-one in reverse side is the error. #### Expected behavior No additional query to call the getBalance () method as it works on the owner side.
admin added the BugInvalid labels 2026-01-22 15:25:10 +01:00
admin closed this issue 2026-01-22 15:25:10 +01:00
Author
Owner

@Ocramius commented on GitHub (Aug 15, 2018):

In one-to-one associations, the owning side must always be loaded in memory: this is intentional/by design.

@Ocramius commented on GitHub (Aug 15, 2018): In one-to-one associations, the owning side must always be loaded in memory: this is intentional/by design.
Author
Owner

@INHack20 commented on GitHub (Aug 15, 2018):

Thanks!

@INHack20 commented on GitHub (Aug 15, 2018): Thanks!
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#6035