2013-11-01 112 views
0

即時嘗試映射三元關係。 ER模型是下一個: enter image description here地圖三元關係

Responsable是一個用戶,Alumno是另一種類型的用戶(學生)。並且TipoRelacion定義Responsable是否是該學生的母親,父親或導師(Alumno)。

所以,我認爲,映射關係(alumno_relacion_responsable)並從其他表中定義bidireccionals OneToMany。

我的實體是:

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 
} 

所以,在relationchip實體:

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 
} 

但是,當測試實體,Symfony的說(負載腳本):

注意:未定義的索引: /var/www/AppsManantiales/vendor/doctrine/orm/lib/Doctrine/ORM/Persisters/BasicEntityPersis ter.php

任何有關我的錯誤的想法?

回答

1

inversedBy設置應該匹配「hijos」和「padres」而不是關聯實體的ID。有一對夫婦的其他問題,ORM \ ID應不關係列指定,並且列也不必規定:

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 
} 

雖然,我相信你有關係翻轉,我想你是尋找更多的東西是這樣的:

  • 許多RESPONSABLE到一個ResponsableAlumno
  • 許多Alumno到一個ResponsableAlumno
  • 一個ResponsableAlumno到許多RESPONSABLE
  • One Responsable Alumno to Many Alumno

或更有可能一個校友對一個ResponsableAlumno,反之亦然。

檢查這裏的關係語法和設置學說完整文檔: http://docs.doctrine-project.org/en/2.1/reference/association-mapping.html