Ver Mensaje Individual
  #5 (permalink)  
Antiguo 15/03/2013, 12:20
wilmer30
 
Fecha de Ingreso: enero-2010
Mensajes: 491
Antigüedad: 14 años, 3 meses
Puntos: 12
Respuesta: Asociaciones en doctrine 2

Precisamente, siguiendo dicho manual, es que las asociaciones son OneToMany de la misma tabla departamento, pero me parece que ya solucioné el problema, auque tengo mis dudas puesto que las asociaciones no me los genera en el MySQL, imagino que lo debo realizar a mano.

este es el modelo:

Código PHP:
Ver original
  1. <?php
  2.  
  3. namespace Entities;
  4.  
  5. use Doctrine\ORM\Mapping as ORM;
  6.  
  7. /**
  8.  * Departamento
  9.  *
  10.  * @Table(name="departamento")
  11.  * @Entity
  12.  */
  13. class Departamento
  14. {
  15.     /**
  16.      * @var integer
  17.      * @ManyToOne(targetEntity="departamento", inversedBy="departamento_id")
  18.      * @JoinColumn(name="id", referencedColumnName="departamento_id")
  19.      *
  20.      * @Column(name="id", type="integer", nullable=false)
  21.      * @Id
  22.      * @GeneratedValue(strategy="IDENTITY")
  23.      */
  24.     private $id;
  25.  
  26.     /**
  27.      * @var string
  28.      *
  29.      * @Column(name="descripcion", type="string", length=200, nullable=false)
  30.      */
  31.     private $descripcion;
  32.  
  33.     /**
  34.      * @var string
  35.      *
  36.      * @Column(name="nombrecargousuario", type="string", length=200, nullable=false)
  37.      */
  38.     private $nombrecargousuario;
  39.  
  40.     /**
  41.      * @var integer
  42.      * @OneToMany(targetEntity="departamento",mappedBy="id")
  43.      *
  44.      * @Column(name="departamento_id", type="integer", nullable=false)
  45.      */
  46.     private $departamentoId;
  47.  
  48.     /**
  49.      * @var string
  50.      *
  51.      * @Column(name="sigla", type="string", length=50, nullable=false)
  52.      */
  53.     private $sigla;
  54.  
  55.     /**
  56.      * @var string
  57.      *
  58.      * @Column(name="formacite", type="string", length=20, nullable=false)
  59.      */
  60.     private $formacite;
  61.  
  62.     /**
  63.      * @var \DateTime
  64.      *
  65.      * @Column(name="fecha", type="date", nullable=false)
  66.      */
  67.     private $fecha;
  68.  
  69.     /**
  70.      * @var string
  71.      *
  72.      * @Column(name="estado", type="string", length=1, nullable=false)
  73.      */
  74.     private $estado;
  75.  
  76.     public function __construct() {
  77.         $this->departamentoId = new \Doctrine\Common\Collections\ArrayCollection();
  78.     }
  79. }

espero críticas o sugerencias