Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

doctrine: refers to owning side field which does not exist (again)

Can't wrap my head around it. I more or less copied from the tutorial, but the profiler throws two errors:

AppBundle\Entity\Brand The association AppBundle\Entity\Brand#devices refers to the owning side field AppBundle\Entity\Device#brands which does not exist.

AppBundle\Entity\Device The association AppBundle\Entity\Device#brand refers to the inverse side field AppBundle\Entity\Brand#brands which does not exist.

class Brand {

    /**
     * @var int
     * @ORM\Column(name="id", type="integer")
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    private $id;

...

    /**
     * @ORM\OneToMany(targetEntity="Device", mappedBy="brands")
     */
    private $devices;
}

and

class Device {
    /**
     * @var int
     * @ORM\Id
     * @ORM\Column(name="id", type="integer")
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    private $id;

...

    /**
     * @ORM\ManyToOne(targetEntity="Brand", inversedBy="devices")
     * @ORM\JoinColumn(name="brand_id", referencedColumnName="id", nullable=true)
     */
    private $brand;
}
like image 468
bluppfisk Avatar asked Feb 06 '23 14:02

bluppfisk


1 Answers

Haven't tested it, but according to docs, it should look something like this

http://doctrine-orm.readthedocs.io/projects/doctrine-orm/en/latest/reference/association-mapping.html#one-to-many-bidirectional

class Brand {

    /**
     * @var int
     * @ORM\Column(name="brand_id", type="integer")
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    private $id;

...

    /**
     * @ORM\OneToMany(targetEntity="Device", mappedBy="brand")
     */
    private $devices;
}

and

class Device {
    /**
     * @var int
     * @ORM\Id
     * @ORM\Column(name="id", type="integer")
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    private $id;

...

    /**
     * @ORM\ManyToOne(targetEntity="Brand", inversedBy="devices")
     * @ORM\JoinColumn(name="brand_id", referencedColumnName="id", nullable=true)
     */
    private $brand;
}
like image 147
lchachurski Avatar answered Feb 09 '23 03:02

lchachurski