Skip to content

Loading…

DDC-1519: Get a catchable error when trying to find an entity by composite PK which contains association key in the identity map #2150

Closed
doctrinebot opened this Issue · 2 comments

2 participants

@doctrinebot

Jira issue originally created by user yethee:

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;
    }
}
@doctrinebot

Comment created by @beberlei:

Merged.

@doctrinebot

Issue was closed with resolution "Fixed"

@beberlei beberlei was assigned by doctrinebot
@doctrinebot doctrinebot added this to the 2.1.5 milestone
@doctrinebot doctrinebot closed this
@doctrinebot doctrinebot added the Bug label
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.