私はsymfony 2で練習を始めました.だから私の質問はこのコマンドについてです:
php app/console doctrine:schema:update --dump-sql
これは、このコマンドの実行結果です。
CREATE TABLE Article (id INT AUTO_INCREMENT NOT NULL, image_id INT NOT NULL, publication TINYINT(1) NOT NULL, date DATETIME NOT NULL, titre VARCHAR(255) NOT NULL, auteur VARCHAR(255) NOT NULL, contenu LONGTEXT NOT NULL, UNIQUE INDEX UNIQ_CD8737FA3DA5256D (image_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB;
CREATE TABLE Image (id INT AUTO_INCREMENT NOT NULL, url VARCHAR(255) NOT NULL, alt VARCHAR(255) NOT NULL, PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB;
CREATE TABLE Voiture (id INT AUTO_INCREMENT NOT NULL, nom VARCHAR(255) NOT NULL, modele VARCHAR(255) NOT NULL, couleur VARCHAR(255) NOT NULL, date_creation DATE NOT NULL, photo LONGTEXT NOT NULL, PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB;
ALTER TABLE Article ADD CONSTRAINT FK_CD8737FA3DA5256D FOREIGN KEY (image_id) REFERENCES Image (id)
このコマンドは私を夢中にさせます。関連するテーブルだけでなく、別のエンティティの他のテーブルも生成します!!!
以前のデータベースをすべて削除しましたが、それでも同じ問題が発生します。
voture tableだけが必要です。他のすべてのテーブルは、他の以前のデータベースに属しています。
どうすればそれを止めることができますか?? これは私のエンティティコードです:
車の実体:
<?php
namespace Younga\RentBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* Car
*/
class Car
{
/**
* @var integer
*/
private $id;
/**
* @var integer
*/
private $nombre;
/**
* @var string
*/
private $nom;
/**
* @var string
*/
private $modele;
/**
* @var string
*/
private $couleur;
/**
* @var \DateTime
*/
private $datecreation;
/**
* @var string
*/
private $photo;
public function __construct()
{
$this->datecreation = new \Datetime;
}
/**
* Get id
*
* @return integer
*/
public function getId()
{
return $this->id;
}
/**
* Set nombre
*
* @param integer $nombre
* @return Car
*/
public function setNombre($nombre)
{
$this->nombre = $nombre;
return $this;
}
/**
* Get nombre
*
* @return integer
*/
public function getNombre()
{
return $this->nombre;
}
/**
* Set nom
*
* @param string $nom
* @return Car
*/
public function setNom($nom)
{
$this->nom = $nom;
return $this;
}
/**
* Get nom
*
* @return string
*/
public function getNom()
{
return $this->nom;
}
/**
* Set modele
*
* @param string $modele
* @return Car
*/
public function setModele($modele)
{
$this->modele = $modele;
return $this;
}
/**
* Get modele
*
* @return string
*/
public function getModele()
{
return $this->modele;
}
/**
* Set couleur
*
* @param string $couleur
* @return Car
*/
public function setCouleur($couleur)
{
$this->couleur = $couleur;
return $this;
}
/**
* Get couleur
*
* @return string
*/
public function getCouleur()
{
return $this->couleur;
}
/**
* Set datecreation
*
* @param \DateTime $datecreation
* @return Car
*/
public function setDatecreation($datecreation)
{
$this->datecreation = $datecreation;
return $this;
}
/**
* Get datecreation
*
* @return \DateTime
*/
public function getDatecreation()
{
return $this->datecreation;
}
/**
* Set photo
*
* @param string $photo
* @return Car
*/
public function setPhoto($photo)
{
$this->photo = $photo;
return $this;
}
/**
* Get photo
*
* @return string
*/
public function getPhoto()
{
return $this->photo;
}
}
コメント エンティティ:
<?php
namespace Younga\RentBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* Commentaire
*/
/**
* @ORM\@ORM\Entity
*
*
*/
class Commentaire
{
/**
* @ORM\ManyToOne(targetEntity="Younga\RentBundle\Entity\Voiture")
* @ORM\JoinColumn(nullable=false)
*
*/
private $voiture;
/**
* @var integer
*/
private $id;
/**
* @var string
*/
private $auteur;
/**
* @var string
*/
private $contenu;
/**
* @var \DateTime
*/
private $datecomment;
/**
* Get id
*
* @return integer
*/
public function getId()
{
return $this->id;
}
/**
* Set auteur
*
* @param string $auteur
* @return Commentaire
*/
public function setAuteur($auteur)
{
$this->auteur = $auteur;
return $this;
}
/**
* Get auteur
*
* @return string
*/
public function getAuteur()
{
return $this->auteur;
}
/**
* Set contenu
*
* @param string $contenu
* @return Commentaire
*/
public function setContenu($contenu)
{
$this->contenu = $contenu;
return $this;
}
/**
* Get contenu
*
* @return string
*/
public function getContenu()
{
return $this->contenu;
}
/**
* Set datecomment
*
* @param \DateTime $datecomment
* @return Commentaire
*/
public function setDatecomment($datecomment)
{
$this->datecomment = $datecomment;
return $this;
}
/**
* Get datecomment
*
* @return \DateTime
*/
public function getDatecomment()
{
return $this->datecomment;
}
/**
* @ORM\prePersist
*/
public function increase()
{
$nbCommentaires = $this->getVoiture()->getNbCommentaires();
$this->getVoiture()->setNbCommentaires($nbCommentaires+1);
}
/**
* @ORM\preRemove
*/
public function decrease()
{
$nbCommentaires = $this->getVoiture()->getNbCommentaires();
$this->getVoiture()->setNbCommentaires($nbCommentaires-1);
}
}
現在のエンティティに関連するテーブルだけが必要です。前回作成した以前のすべてのエンティティを呼び出します。よろしくお願いします。私の英語で申し訳ありません。