[BUG] One to one relation breaks cache entities relations #5271

Open
opened 2026-01-22 15:03:11 +01:00 by admin · 5 comments
Owner

Originally created by @BourotBenjamin on GitHub (Sep 23, 2016).

I have an entity like :

/**
 * User
 *
 * @ORM\Table(name="user")
 * @ORM\Entity()
 * @ORM\Cache(usage="NONSTRICT_READ_WRITE", region="region_user")
 */
class Language
{ 

    /**
     * @ORM\Cache(usage="NONSTRICT_READ_WRITE")
     * @ORM\OneToOne(targetEntity="UserInfos", mappedBy="user", cascade={"remove"})
     */
    private $infos = null; 


    /**
     * @ORM\ManyToOne(targetEntity="Language")
     * @ORM\JoinColumn(name="actual_lang_id", referencedColumnName="id")
      * @ORM\Cache(usage="NONSTRICT_READ_WRITE")
     */
    private $actualLanguage;

}

I tried to investigate why the cache returns users with actualLanguage = null ( because every user hav an actual Language )

I found that in Doctrine\ORM\Cache\DefaultQueryCache, the function get doesn't seems to resolve my Users linked entities right.

As my users have a One to One relation, I found in $rsm->relationMap, I have the User to Infos relation.
So, my user $hasRelation is true so it doesn't resolveAssociationEntries.

My user doesn't have any $entry['associations'] neither so it don't resolveAssociationEntries after.

I don't know whats wrong here.
I don't know if I don't have any associations because I didn't requested any entities in EAGER mode and if it's normal.

Maybe the enities needs to resolveAssociationEntries each time.
Why don't you resolve them if you have oneToOne associations ?

The only thing I know is that my entities aren't complete when I get them back from cache.

Thanks in advance

Originally created by @BourotBenjamin on GitHub (Sep 23, 2016). I have an entity like : ``` /** * User * * @ORM\Table(name="user") * @ORM\Entity() * @ORM\Cache(usage="NONSTRICT_READ_WRITE", region="region_user") */ class Language { /** * @ORM\Cache(usage="NONSTRICT_READ_WRITE") * @ORM\OneToOne(targetEntity="UserInfos", mappedBy="user", cascade={"remove"}) */ private $infos = null; /** * @ORM\ManyToOne(targetEntity="Language") * @ORM\JoinColumn(name="actual_lang_id", referencedColumnName="id") * @ORM\Cache(usage="NONSTRICT_READ_WRITE") */ private $actualLanguage; } ``` I tried to investigate why the cache returns users with actualLanguage = null ( because every user hav an actual Language ) I found that in `Doctrine\ORM\Cache\DefaultQueryCache`, the function `get` doesn't seems to resolve my Users linked entities right. As my users have a One to One relation, I found in `$rsm->relationMap`, I have the User to Infos relation. So, my user `$hasRelation` is true so it doesn't `resolveAssociationEntries`. My user doesn't have any `$entry['associations']` neither so it don't `resolveAssociationEntries` after. I don't know whats wrong here. I don't know if I don't have any associations because I didn't requested any entities in EAGER mode and if it's normal. Maybe the enities needs to resolveAssociationEntries each time. Why don't you resolve them if you have oneToOne associations ? The only thing I know is that my entities aren't complete when I get them back from cache. Thanks in advance
admin added the BugMissing Tests labels 2026-01-22 15:03:11 +01:00
Author
Owner

@phoenixgao commented on GitHub (Dec 26, 2017):

I have exactly the same issue @BourotBenjamin did you figure out why?

@phoenixgao commented on GitHub (Dec 26, 2017): I have exactly the same issue @BourotBenjamin did you figure out why?
Author
Owner

@Ocramius commented on GitHub (Dec 26, 2017):

Is this still valid for 2.6.0?

On 26 Dec 2017 11:22, "Phoenix Gao" notifications@github.com wrote:

I have exactly the same issue


You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
https://github.com/doctrine/doctrine2/issues/6051#issuecomment-353951654,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AAJakB4AaaAVhxVOPfl45HAyiepv3Q8Cks5tEMjwgaJpZM4KFJ1p
.

@Ocramius commented on GitHub (Dec 26, 2017): Is this still valid for 2.6.0? On 26 Dec 2017 11:22, "Phoenix Gao" <notifications@github.com> wrote: > I have exactly the same issue > > — > You are receiving this because you are subscribed to this thread. > Reply to this email directly, view it on GitHub > <https://github.com/doctrine/doctrine2/issues/6051#issuecomment-353951654>, > or mute the thread > <https://github.com/notifications/unsubscribe-auth/AAJakB4AaaAVhxVOPfl45HAyiepv3Q8Cks5tEMjwgaJpZM4KFJ1p> > . >
Author
Owner

@phoenixgao commented on GitHub (Dec 26, 2017):

@Ocramius Currently I'm using doctrine/orm 2.5.13, will try 2.6

@phoenixgao commented on GitHub (Dec 26, 2017): @Ocramius Currently I'm using doctrine/orm 2.5.13, will try 2.6
Author
Owner

@vincequeiroz commented on GitHub (Jan 22, 2018):

I have the same issue too, but I'm use class table inheritance with second level cache.

@Ocramius I'm rollback to version 2.5.14 and it works.

@vincequeiroz commented on GitHub (Jan 22, 2018): I have the same issue too, but I'm use class table inheritance with second level cache. @Ocramius I'm rollback to version 2.5.14 and it works.
Author
Owner

@Ocramius commented on GitHub (Jan 26, 2018):

@vincequeiroz your scenario is probably different, since @phoenixgao experiences this issue on 2.5.x

@Ocramius commented on GitHub (Jan 26, 2018): @vincequeiroz your scenario is probably different, since @phoenixgao experiences this issue on `2.5.x`
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#5271