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;
}
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;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With