Doctrine 2 - ORM
  1. Doctrine 2 - ORM
  2. DDC-1519

Get a catchable error when trying to find an entity by composite PK which contains association key in the identity map

    Details

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

      Description

      I got a сatchable error when merging entity that has a composite PK with association FK:

      Catchable Fatal Error: Object of class TestBundle\Entity\Foo could not be converted to string in /home/context/httpd/vendor/doctrine/lib/Doctrine/ORM/UnitOfWork.php line 2606

      Entities and their mapping:

      use Doctrine\ORM\Mapping as ORM;
      use Doctrine\Common\Collections\ArrayCollection;
      
      /**
       * @ORM\Entity
       */
      class Foo
      {
          /**
           * @ORM\Column(type="integer")
           * @ORM\Id
           * @ORM\GeneratedValue
           */
          public $id;
      
          /**
           * @ORM\Column(type="string", nullable=true)
           */
          public $name;
      
          /**
           * @ORM\OneToMany(targetEntity="FooHasBar", mappedBy="foo", cascade={"persist", "remove", "merge"})
           */
          public $children;
      
          public function __construct()
          {
              $this->children = new ArrayCollection();
          }
      }
      
      /**
       * @ORM\Entity
       */
      class Bar
      {
          /**
           * @ORM\Column(type="integer")
           * @ORM\Id
           * @ORM\GeneratedValue
           */
          public $id;
      
          /**
           * @ORM\Column(type="string", nullable=true)
           */
          public $name;
      }
      
      /**
       * @ORM\Entity
       */
      class FooHasBar
      {
          /**
           * @ORM\Id
           * @ORM\ManyToOne(targetEntity="Foo", inversedBy="children")
           * @ORM\JoinColumn(name="foo_id", referencedColumnName="id", nullable=false)
           */
          public $foo;
      
          /**
           * @ORM\Column(type="integer")
           * @ORM\Id
           */
          public $mode;
      
          /**
           * @ORM\ManyToOne(targetEntity="Bar")
           * @ORM\JoinColumn(name="bar_id", referencedColumnName="id", nullable=false)
           */
          public $bar;
      
          public function __construct(Foo $foo, Bar $bar, $mode)
          {
              $this->foo = $foo;
              $this->bar = $bar;
              $this->mode = $mode;
          }
      }
      

        Activity

        Hide
        Benjamin Eberlei added a comment -

        Merged.

        Show
        Benjamin Eberlei added a comment - Merged.

          People

          • Assignee:
            Benjamin Eberlei
            Reporter:
            Denis Vasilev
          • Votes:
            1 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: