Doctrine 2 - ORM
  1. Doctrine 2 - ORM
  2. DDC-2034

getPartialReference returns partial entities for non existent entities

    Details

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

      Description

      $variant = $em->getPartialReference('Entity\Variant', -1);
      echo $variant->getVariantId();
      

      prints -1. Is it an expected behavior or a bug? Shouldn't a check be made to prevent creating new instances for ids that do not exist?

        Activity

        Hide
        Christophe Coevoet added a comment -

        Well, the purpose of getPartialReference is to return a reference without querying the database. So it cannot know if the id exists.
        https://github.com/doctrine/doctrine2/blob/master/lib/Doctrine/ORM/EntityManager.php#L481

        Show
        Christophe Coevoet added a comment - Well, the purpose of getPartialReference is to return a reference without querying the database. So it cannot know if the id exists. https://github.com/doctrine/doctrine2/blob/master/lib/Doctrine/ORM/EntityManager.php#L481
        Hide
        Oleg Namaka added a comment -

        Ok, in that case a user is responsible for providing a valid id. But what is a use case for such an entity? Can someone give me a real example?

        Show
        Oleg Namaka added a comment - Ok, in that case a user is responsible for providing a valid id. But what is a use case for such an entity? Can someone give me a real example?
        Hide
        Benjamin Eberlei added a comment -

        the use case was partially removed by proxy objects now being capable of returning the id without querying.

        Show
        Benjamin Eberlei added a comment - the use case was partially removed by proxy objects now being capable of returning the id without querying.

          People

          • Assignee:
            Benjamin Eberlei
            Reporter:
            Oleg Namaka
          • Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: