I've created two Entity, and i try to create a custom relation between them, without using the default syntax.
See :
/**
* @ORM\Entity(repositoryClass=LandRepository::class)
* @ORM\HasLifecycleCallbacks()
*/
class Land
{
/**
* @ORM\Id()
* @ORM\GeneratedValue()
* @ORM\Column(type="integer")
*/
private $id;
/**
* @ORM\Column(type="string", length=255)
*/
private $libelle;
/**
* @ORM\Column(type="integer")
*/
private $uid;
/**
* @ORM\OneToMany(targetEntity=Ride::class, mappedBy="uidparent")
*/
private $rides;
}
/**
* @ORM\Entity(repositoryClass=RideRepository::class)
* @ORM\HasLifecycleCallbacks()
*/
class Ride
{
/**
* @ORM\Id()
* @ORM\GeneratedValue()
* @ORM\Column(type="integer")
*/
private $id;
/**
* @ORM\Column(type="string", length=255)
*/
private $libelle;
/**
* @ORM\ManyToOne(targetEntity=Land::class, inversedBy="rides")
* @ORM\JoinColumn(name="uidparent", referencedColumnName="uid")
*/
private $uidparent;
}
Tables are correctly created, but the last instruction have an error.
In MySQL, i made some test, and i need to create an index on "uid" column in "land" table. So, i changed the header of my class "Land" to force the index
/**
* @ORM\Entity(repositoryClass=LandRepository::class)
* @ORM\Table(name="land",indexes={@ORM\Index(columns={"uid"})})
* @ORM\HasLifecycleCallbacks()
*/
class Land
{
/ ... /
}
I don't understand why i need to specify this index creation.
I hope to have something like this :
(PS : I know i can use the classic syntax (using in my entity Ride a column auto named "land_id") but I want to understand and master this alternative syntax to manage future complex entities and associations)
Thanks !