DDC-1437: Strange behavior with proxied classes,expected to get entity, but returned identifier. #1802

Closed
opened 2026-01-22 13:26:31 +01:00 by admin · 3 comments
Owner

Originally created by @doctrinebot on GitHub (Oct 19, 2011).

Originally assigned to: @beberlei on GitHub.

Jira issue originally created by user goetas:

I have the following xml mapping:

User:
  <entity name="User" table="user">
    <id name="id" type="integer" column="id">
      <generator strategy="SEQUENCE"/>
    </id>
    <field name="name" type="string" column="name"/>
   </entity>

SuperUser:
  <entity name="SuperUser" table="superuser">

    <id name="user" type="integer" column="user_id" association-key="true"/>

    <one-to-one field="user" target-entity="User">
      <join-columns>
        <join-column name="user_id" referenced-column-name="id"/>
      </join-columns>
    </one-to-one>

  </entity>

From this mapping i have generated the php classes.

In my application, when the SuperUser class is proxied, SuperUser::getUser() method looks like this:

public function getUser(){

        if ($this->*_isInitialized_* === false) {
            return $this->_identifier["user"];
        }
        $this->**load();
        return parent::getUser();
}

When i call $usperuser->getUser() the expected return value is the User class instance; but the current implementation returns only user id (contained in $this->_identifier["user"]).

In this behavior is also involved private function ProxyFactory::isShortIdentifierGetter($method, $class)

Some solutions proposed by me, can be:

  • remove this behavior
  • during proxy generation, add in this case a method called getUserId, and this method can return user id (but in this case, the behavior continues to be strange because is available only for proxied classes).

(sorry for my english)

Originally created by @doctrinebot on GitHub (Oct 19, 2011). Originally assigned to: @beberlei on GitHub. Jira issue originally created by user goetas: I have the following xml mapping: ``` xml User: <entity name="User" table="user"> <id name="id" type="integer" column="id"> <generator strategy="SEQUENCE"/> </id> <field name="name" type="string" column="name"/> </entity> SuperUser: <entity name="SuperUser" table="superuser"> <id name="user" type="integer" column="user_id" association-key="true"/> <one-to-one field="user" target-entity="User"> <join-columns> <join-column name="user_id" referenced-column-name="id"/> </join-columns> </one-to-one> </entity> ``` From this mapping i have generated the php classes. In my application, when the `SuperUser` class is proxied, `SuperUser::getUser()` method looks like this: ``` public function getUser(){ if ($this->*_isInitialized_* === false) { return $this->_identifier["user"]; } $this->**load(); return parent::getUser(); } ``` When i call `$usperuser->getUser()` the expected return value is the User class instance; but the current implementation returns only user id (contained in `$this->_identifier["user"]`). In this behavior is also involved private function `ProxyFactory::isShortIdentifierGetter($method, $class)` Some solutions proposed by me, can be: - remove this behavior - during proxy generation, add in this case a method called getUserId, and this method can return user id (but in this case, the behavior continues to be strange because is available only for proxied classes). (sorry for my english)
admin added the Bug label 2026-01-22 13:26:31 +01:00
admin closed this issue 2026-01-22 13:26:32 +01:00
Author
Owner

@doctrinebot commented on GitHub (Oct 19, 2011):

Comment created by @beberlei:

very recent bug in master, i will fix it.

@doctrinebot commented on GitHub (Oct 19, 2011): Comment created by @beberlei: very recent bug in master, i will fix it.
Author
Owner

@doctrinebot commented on GitHub (Oct 19, 2011):

Comment created by @beberlei:

fixed in master

@doctrinebot commented on GitHub (Oct 19, 2011): Comment created by @beberlei: fixed in master
Author
Owner

@doctrinebot commented on GitHub (Oct 19, 2011):

Issue was closed with resolution "Fixed"

@doctrinebot commented on GitHub (Oct 19, 2011): Issue was closed with resolution "Fixed"
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#1802