0

我开始练习 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)

这个命令让我抓狂,它不仅会生成相关表,还会生成另一个实体的其他表!!!

我删除了所有以前的数据库,但仍然遇到同样的问题。

我只需要voiture 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);
      }
}

我只需要与当前实体相关的表。它调用我上次创建的所有先前实体。在此先感谢并为我的英语感到抱歉。

4

1 回答 1

0

我想您的实体中有注释,例如:

namespace Your\OwnBundle\Entity;

use Whatever\You\Use\Here;

/**
 * Myentity
 *
 * @ORM\Table(name="myentity")
 * @ORM\Entity
 */
class Myentity
{
    /**
     * @var integer
     *
     * @ORM\Id
     * @ORM\Column(name="id", type="smallint", nullable=false)
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    private $id;
    //... more code
{

尝试删除注释@ORM\Table(name="myentity")@ORM\Entity. 这样一来,我认为 Symfony 不会将它们视为要考虑的实体。

希望我能帮到你,伙计!

于 2013-07-09T07:25:16.663 回答