Reputation: 2029
im try to map a ternary relationship. The ER Model is the next:
Responsable is an user, Alumno is another type of user (a student). And TipoRelacion define if Responsable is mother, father or tutor of the student (Alumno).
So, i think, map the relationship (alumno_relacion_responsable) and define bidireccionals OneToMany from other tables.
My entities are:
class Responsable{
// other declarations
/**
* @ORM\OneToMany(targetEntity="ResponsableAlumno", mappedBy="alumno")
*/
protected $hijos;
// More declarations
}
class Alumno{
// other declarations
/**
* @ORM\OneToMany(targetEntity="ResponsableAlumno", mappedBy="responsable")
*/
protected $padres;
// More declarations
}
So, in the relationchip entity:
Class ResponsableAlumno{
/**
* @ORM\Id
* @ORM\Column(name="Responsable_IdUsuario")
* @ORM\ManyToOne(targetEntity="Responsable", inversedBy="idusuario")
* @ORM\JoinColumn(name="Responsable_IdUsuario", referencedColumnName="idusuario")
*/
protected $responsable;
/**
* @ORM\Id
* @ORM\Column(name="Alumno_IdUsuario")
* @ORM\ManyToOne(targetEntity="Alumno", inversedBy="idusuario")
* @ORM\JoinColumn(name="Alumno_IdUsuario", referencedColumnName="idusuario")
*/
protected $alumno;
// Other declarations
}
But, when test the entities, Symfony says (on load script):
Notice: Undefined index: alumno in /var/www/AppsManantiales/vendor/doctrine/orm/lib/Doctrine/ORM/Persisters/BasicEntityPersister.php
Any ideas about what is my error ?.
Upvotes: 0
Views: 1340
Reputation: 21
The inversedBy setting should match the "hijos" and "padres" not the ID of the associated entity. There are a couple other problems, ORM\Id should not be specified on the relational columns, and the Column also need not be specified:
class ResponsableAlumno{
/**
* @ORM\ManyToOne(targetEntity="Responsable", inversedBy="hijos")
* @ORM\JoinColumn(name="Responsable_IdUsuario", referencedColumnName="idusuario")
*/
protected $responsable;
/**
* @ORM\ManyToOne(targetEntity="Alumno", inversedBy="padres")
* @ORM\JoinColumn(name="Alumno_IdUsuario", referencedColumnName="idusuario")
*/
protected $alumno;
// Other declarations
}
Though, I do believe you have the relations flipped, I imagine you are looking for something more like this:
Or more likely One Alumno to One ResponsableAlumno and vice versa.
Check here for full documentation on the relationship syntax and settings for Doctrine: http://docs.doctrine-project.org/en/2.1/reference/association-mapping.html
Upvotes: 1