I have three entities: 'Usuario', 'Estudiante' and 'Administrador'. 'Usuario' represents the users in the application, that can be 'Estudiante' or 'Administrador'. How can I relate this?
I show you the three entities:
Entity 'Usuario'
/**
* @ORM\Entity()
* @DoctrineAssert\UniqueEntity(fields = {"id_usuario", "guid"})
*/
class Usuario
{
/**
* @ORM\Id
* @ORM\OneToOne(targetEntity="Estudiante", inversedBy="id_estudiante")
* @ORM\JoinColumn(name="usuario_id", referencedColumnName="id_usuario")
* @ORM\OneToOne(targetEntity="Administrador", inversedBy="id_administrador")
* @ORM\JoinColumn(name="usuario_id", referencedColumnName="id_usuario")
**/
protected $id_usuario;
/**
* @ORM\Column(type="string")
*/
protected $guid;
(...)
Entity 'Estudiante'
class Estudiante implements UserInterface
{
/**
* @ORM\Id
* @ORM\Column(type="string",length=100)
* @Assert\NotBlank(message = "Por favor, indica tu email")
* @Assert\Email(message = "El email introducido no es válido",
* checkMX=true)
**/
protected $id_estudiante;
/**
* @ORM\Column(type="string")
* @Assert\Length(min=4, max=8, minMessage = "La contraseña debe contener entre 6 y 12 caracteres", maxMessage = "La contraseña debe contener entre 6 y 12 caracteres")
*/
protected $password;
/**
* @ORM\Column(type="string")
*/
protected $salt;
(...)
Entity 'Administrador'
/**
* @ORM\Entity()
* @DoctrineAssert\UniqueEntity(fields = {"id_estudiante", "guid"})
*/
class Administrador implements UserInterface
{
/**
* @ORM\Id
* @ORM\Column(type="string",length=100)
* @Assert\NotBlank(message = "Por favor, indica tu email")
* @Assert\Email(message = "El email introducido no es válido",
* checkMX=true)
**/
protected $id_administrador;
/**
* @ORM\Column(type="string")
* @Assert\Length(min=4, max=8, minMessage = "La contraseña debe contener entre 6 y 12 caracteres", maxMessage = "La contraseña debe contener entre 6 y 12 caracteres")
*/
protected $password;
/**
* @ORM\Column(type="string")
*/
protected $salt;
(...)
Please, how can I do that? I need to separate 'Estudiante' and 'Administrador' because if someone is registered as an 'Estudiante' and later wants to became an 'Administrador', I only have to move the field from 'Administrador' to 'Estudiante'. So another questions would be... is there another way to do that change?