Doctrine 2 - ORM
  1. Doctrine 2 - ORM
  2. DDC-1437

Strange behavior with proxied classes,expected to get entity, but returned identifier.

    Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 2.2
    • Component/s: ORM
    • Security Level: All
    • Labels:
      None

      Description

      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)

        Activity

        Hide
        Benjamin Eberlei added a comment -

        very recent bug in master, i will fix it.

        Show
        Benjamin Eberlei added a comment - very recent bug in master, i will fix it.
        Hide
        Benjamin Eberlei added a comment -

        fixed in master

        Show
        Benjamin Eberlei added a comment - fixed in master

          People

          • Assignee:
            Benjamin Eberlei
            Reporter:
            Asmir Mustafic
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: