Doctrine 2 - ORM
  1. Doctrine 2 - ORM
  2. DDC-3068

EntityManager::find does not accept an array of object as a primary key

    Details

    • Type: Improvement Improvement
    • Status: Resolved
    • Priority: Minor Minor
    • Resolution: Fixed
    • Affects Version/s: 2.3, 2.4, Git Master
    • Fix Version/s: 2.5
    • Component/s: ORM
    • Security Level: All
    • Labels:
      None

      Description

      According to the documentation, EntityManager::find should return one entity given it's primary key. When a primary key of an entity is composed of multiple associations, one (me ) would expect that the following works, but it doesn't:

      $entity = $_em->find('My\EntityClass', array(
          'assoc1' => $instance1,
          'assoc2' => $instance2
      ));
      PHP Fatal error:  Object of class My\EntityClass could not be converted to string
      

      The only working way I've found is the following:

      $entity = $_em->find('My\EntityClass', array(
          'assoc1' => $instance1->getId(),
          'assoc2' => $instance2->getId()
      ));
      

      I think that this second scenario is not correct, since expose implementation details.

      I've created a patch on my github fork, I'll create a pull request ASAP.

        Activity

        Show
        Guilherme Blanco added a comment - As of https://github.com/doctrine/doctrine2/commit/10a0daf6203b6d2ea0c92e30edb07ca7e83058b3 issue was fixed.

          People

          • Assignee:
            Guilherme Blanco
            Reporter:
            Giorgio Premi
          • Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: