Robię to komendą generate:doctrine:entities i nic, nie dodaje żadnych metod, mimo że konsola nie wyrzuca błędów.
Od początku.
Wygenerowałem bazę na podstawie diagramu ER i utworzyłem ją na serwerze. Tę bazę komendą doctrine:mapping:import i doctrine:mapping:convert annotation i doctrine:generate:entities sprowadziłem do projektu Symfony i utworzyłem modele.
Dokumentacja mówi, że te komendy nie generują w pełni kodu i trzeba ręcznie dodać parę rzeczy.
(If you want to have a one-to-many relationship, you will need to add it manually into the entity or to the generated XML or YAML files. Add a section on the specific entities for one-to-many defining the inversedBy and the mappedBy pieces.)
Dodałem brakujące adnotacje relacji OneToMany i zmodyfikowałem relacje ManyToOne . Po tych zmianach uruchomiłem komendę doctrine:generate:entities i w efekcie nie dodał do klas żadnych nowych metod takich jak __construct() czy addxxx().
Co źle robię?
Dla przykładu wkleję dwa modele powiązane relacją ManyToOne. Ręcznie dodałem adnotacje OneToMany w klasie Kategoria.php i zmodyfikowałem ManyToOne w klasie Ksiazka.php.
ręcznie dodałem kod linii 32-35
#Kategoria.php <?php namespace AppBundle\Entity; use Doctrine\ORM\Mapping as ORM; /** * Kategoria * * @ORM\Table(name="kategoria") * @ORM\Entity */ class Kategoria { /** * @var string * * @ORM\Column(name="nazwa", type="string", length=45, nullable=true) */ private $nazwa; /** * @var integer * * @ORM\Column(name="idKategoria", type="integer") * @ORM\Id * @ORM\GeneratedValue(strategy="IDENTITY") */ private $idkategoria; /** * @ORM\OneToMany(targetEntity="Ksiazka", mappedBy="kategoria") */ protected $ksiazki; /** * Set nazwa * * @param string $nazwa * @return Kategoria */ public function setNazwa($nazwa) { $this->nazwa = $nazwa; return $this; } /** * Get nazwa * * @return string */ public function getNazwa() { return $this->nazwa; } /** * Get idkategoria * * @return integer */ public function getIdkategoria() { return $this->idkategoria; } }
modyfikowałem kod linii 78-86
Ksiazka.php <?php namespace AppBundle\Entity; use Doctrine\ORM\Mapping as ORM; /** * Ksiazka * * @ORM\Table(name="ksiazka", indexes={@ORM\Index(name="idKategoria_idx", columns={"idKategoria"})}) * @ORM\Entity */ class Ksiazka { /** * @var string * * @ORM\Column(name="autor", type="string", length=45, nullable=true) */ private $autor; /** * @var string * * @ORM\Column(name="opis", type="text", length=65535, nullable=true) */ private $opis; /** * @var string * * @ORM\Column(name="cena", type="decimal", precision=10, scale=2, nullable=true) */ private $cena; /** * @var string * * @ORM\Column(name="obrazek", type="string", length=45, nullable=true) */ private $obrazek; /** * @var string * * @ORM\Column(name="wydawnictwo", type="string", length=45, nullable=true) */ private $wydawnictwo; /** * @var string * * @ORM\Column(name="rokWydania", type="string", length=45, nullable=true) */ private $rokwydania; /** * @var string * * @ORM\Column(name="isbn", type="string", length=45) * @ORM\Id * @ORM\GeneratedValue(strategy="IDENTITY") */ private $isbn; // Było. Automatycznie wygenerowane bez inversedBy. // /** // * @var \AppBundle\Entity\Kategoria // * // * @ORM\ManyToOne(targetEntity="AppBundle\Entity\Kategoria") // * @ORM\JoinColumns({ // * @ORM\JoinColumn(name="idKategoria", referencedColumnName="idKategoria") // * }) // */ // private $idkategoria; /** * @var \AppBundle\Entity\Kategoria * * @ORM\ManyToOne(targetEntity="AppBundle\Entity\Kategoria", inversedBy="ksiazki") * @ORM\JoinColumns({ * @ORM\JoinColumn(name="idKategoria", referencedColumnName="idKategoria") * }) */ private $kategoria; /** * @ORM\OneToMany(targetEntity="Zamowienie_Produkt", mappedBy="ksiazka") */ protected $zamowienie_produkty; /** * Set autor * * @param string $autor * @return Ksiazka */ public function setAutor($autor) { $this->autor = $autor; return $this; } /** * Get autor * * @return string */ public function getAutor() { return $this->autor; } /** * Set opis * * @param string $opis * @return Ksiazka */ public function setOpis($opis) { $this->opis = $opis; return $this; } /** * Get opis * * @return string */ public function getOpis() { return $this->opis; } /** * Set cena * * @param string $cena * @return Ksiazka */ public function setCena($cena) { $this->cena = $cena; return $this; } /** * Get cena * * @return string */ public function getCena() { return $this->cena; } /** * Set obrazek * * @param string $obrazek * @return Ksiazka */ public function setObrazek($obrazek) { $this->obrazek = $obrazek; return $this; } /** * Get obrazek * * @return string */ public function getObrazek() { return $this->obrazek; } /** * Set wydawnictwo * * @param string $wydawnictwo * @return Ksiazka */ public function setWydawnictwo($wydawnictwo) { $this->wydawnictwo = $wydawnictwo; return $this; } /** * Get wydawnictwo * * @return string */ public function getWydawnictwo() { return $this->wydawnictwo; } /** * Set rokwydania * * @param string $rokwydania * @return Ksiazka */ public function setRokwydania($rokwydania) { $this->rokwydania = $rokwydania; return $this; } /** * Get rokwydania * * @return string */ public function getRokwydania() { return $this->rokwydania; } /** * Get isbn * * @return string */ public function getIsbn() { return $this->isbn; } /** * Set idkategoria * * @param \AppBundle\Entity\Kategoria $idkategoria * @return Ksiazka */ public function setIdkategoria(\AppBundle\Entity\Kategoria $idkategoria = null) { $this->idkategoria = $idkategoria; return $this; } /** * Get idkategoria * * @return \AppBundle\Entity\Kategoria */ public function getIdkategoria() { return $this->idkategoria; } /** * @var \AppBundle\Entity\Kategoria */ private $idkategoria; }