Ver Mensaje Individual
  #6 (permalink)  
Antiguo 15/03/2013, 13:00
Avatar de masterpuppet
masterpuppet
Software Craftsman
 
Fecha de Ingreso: enero-2008
Ubicación: Montevideo, Uruguay
Mensajes: 3.550
Antigüedad: 16 años, 3 meses
Puntos: 845
Respuesta: Asociaciones en doctrine 2

Te repito lo mismo, en id tienes metadata de mas y departamentoId debería ser departamento si es una unidad o bien departamentos si es una colección, luego en la metadata mapeas la clave foranea con el nombre que quieras pero a nivel de domain model es un objeto no el id del mismo.

Código PHP:
Ver original
  1. use Doctrine\Common\Collections\ArrayCollection;
  2.  
  3. /** @Entity **/
  4. class Departamento
  5. {
  6.  
  7.     /**
  8.      * @var integer
  9.      *
  10.      * @Column(name="id", type="integer", nullable=false)
  11.      * @Id
  12.      * @GeneratedValue(strategy="IDENTITY")
  13.      */
  14.     private $id;
  15.  
  16.     /**
  17.      * @var string
  18.      *
  19.      * @Column(name="descripcion", type="string", length=200)
  20.      */
  21.     private $descripcion;
  22.  
  23.     /**
  24.      * @OneToMany(targetEntity="Departamento", mappedBy="parent")
  25.      **/
  26.     private $children;
  27.  
  28.     /**
  29.      * @ManyToOne(targetEntity="Departamento", inversedBy="children")
  30.      * @JoinColumn(name="parent_id", referencedColumnName="id")
  31.      **/
  32.     private $parent;
  33.  
  34.     public function __construct()
  35.     {
  36.         $this->children = new ArrayCollection;
  37.     }
  38. }
__________________
http://es.phptherightway.com/
thats us riders :)

Última edición por masterpuppet; 15/03/2013 a las 13:05