2017-04-01 72 views
0

學說不會爲ManyToMany關係生成數據庫模式。學說不會生成數據庫模式ManyToMany關係

C:\ Bitnami \ wampstack-5.6.30-0 \ Apache2的\ htdocs中\ typejoy.biz> PHP廠商\原則\ ORM \ BIN \學說ORM:架構工具:創建

創建兩個表兩個實體testChi和testPar,但不創建@JoinTable「tParChiMTM」。

實體testChi

<?php 

namespace LogBundle\Entity; 

use Doctrine\Common\Collections\ArrayCollection; 
use Doctrine\ORM\Mapping\Entity; 
use Doctrine\ORM\Mapping\Table; 
use Doctrine\ORM\Mapping\Index; 
use Doctrine\ORM\Mapping\Id; 
use Doctrine\ORM\Mapping\GeneratedValue; 
use Doctrine\ORM\Mapping\Column; 
use Doctrine\ORM\Mapping\JoinTable; 
use Doctrine\ORM\Mapping\OneToOne; 
use Doctrine\ORM\Mapping\OneToMany; 
use Doctrine\ORM\Mapping\ManyToOne; 
use Doctrine\ORM\Mapping\ManyToMany; 
use LogBundle\Entity\testPar; 


/** 
* @Table(name="ttestchi") 
* @Entity() 
*/ 
class testChi { 

    /** 
    * @var integer 
    * 
    * @Column(name="id", type="integer") 
    * @Id 
    * @GeneratedValue(strategy="AUTO") 
    */ 
    private $id; 
/** @Column (name="name", type="string", length=50, unique=false, nullable=true) */ 
    private $name; 

/** @ManyToMany (targetEntity="testPar", mappedBy="chiMTM") */ 
    private $parMTM; 


    public function __construct() { 
     $this->chiMTM = new ArrayCollection(); 
    } 

    /** 
    * Get id 
    * 
    * @return integer 
    */ 
    public function getId() 
    { 
     return $this->id; 
    }      
    /** 
    * Get name 
    * 
    * @return integer 
    */ 
    public function getName() 
    { 
     return $this->name; 
    } 

    /** 
    * Set name 
    * @param integer $name 
    * @return name 
    */ 
    public function setName($name) 
    { 
     $this->name = $name; 

     return $this; 
    }  



    //make you have to serialize, deserialize entity here ??? 
    /** 
    * Get parMTM 
    * 
    * @return LogBundle\Entity\ParMTM 
    */ 
    public function getParMTM() 
    { 
     return $this->parMTM; 
    } 

    /** 
    * Remove parMTM 
    * 
    * @param \LogBundle\Entity\testPar $parMTM 
    */ 
    public function removeParMTM (\LogBundle\Entity\testPar $parMTM) 
    { 
     if ($this->hasParMTM($parMTM)) { 
      $this->parMTM->removeElement($parMTM); 
     } 
    } 

    /** 
    * Add parMTM 
    * 
    * @param \LogBundle\Entity\testPar $parMTM 
    * 
    * @return ParMTM 
    */ 
    public function addParMTM(\LogBundle\Entity\testPar $parMTM) 
    { 
     if (!$this->hasParMTM($parMTM)) { 
      $this->parMTM[] = $parMTM; 
     } 

     return $this; 
    } 

    /** 
    * @param \LogBundle\Entity\testPar $parMTM 
    * @return bool 
    */ 
    public function hasParMTM($parMTM) 
    { 
     if($this->getParMTM()) { 
      return $this->getParMTM()->contains($parMTM); 
     } 
    } 



    /** 
    * Return Entity as string 
    * 
    * @return string String representation of this class 
    */ 
    public function __toString() 
    { 
     return strval($this->id); 
    } 

} 

實體testPar

<?php 

namespace LogBundle\Entity; 

use Doctrine\Common\Collections\ArrayCollection; 
use Doctrine\ORM\Mapping\Entity; 
use Doctrine\ORM\Mapping\Table; 
use Doctrine\ORM\Mapping\Index; 
use Doctrine\ORM\Mapping\Id; 
use Doctrine\ORM\Mapping\GeneratedValue; 
use Doctrine\ORM\Mapping\Column; 
use Doctrine\ORM\Mapping\JoinTable; 
use Doctrine\ORM\Mapping\OneToOne; 
use Doctrine\ORM\Mapping\OneToMany; 
use Doctrine\ORM\Mapping\ManyToOne; 
use Doctrine\ORM\Mapping\ManyToMany; 
use LogBundle\Entity\testChi; 


/** 
* @Table(name="ttestpar") 
* @Entity() 
*/ 
class testPar { 

    /** 
    * @var integer 
    * 
    * @Column(name="id", type="integer") 
    * @Id 
    * @GeneratedValue(strategy="AUTO") 
    */ 
    private $id; 
/** @Column (name="name", type="string", length=50, unique=false, nullable=true) */ 
    private $name; 

/** @ManyToMany (targetEntity="testChi", inversedBy="parMTM") */ 
/** @JoinTable (name="tParChiMTM") */ 
    private $chiMTM; 


    public function __construct() { 
     $this->chiMTM = new ArrayCollection(); 
    } 

    /** 
    * Get id 
    * 
    * @return integer 
    */ 
    public function getId() 
    { 
     return $this->id; 
    }      
    /** 
    * Get name 
    * 
    * @return integer 
    */ 
    public function getName() 
    { 
     return $this->name; 
    } 

    /** 
    * Set name 
    * @param integer $name 
    * @return name 
    */ 
    public function setName($name) 
    { 
     $this->name = $name; 

     return $this; 
    }  



    //make you have to serialize, deserialize entity here ??? 
    /** 
    * Get chiMTM 
    * 
    * @return LogBundle\Entity\ChiMTM 
    */ 
    public function getChiMTM() 
    { 
     return $this->chiMTM; 
    } 

    /** 
    * Remove chiMTM 
    * 
    * @param \LogBundle\Entity\testChi $chiMTM 
    */ 
    public function removeChiMTM (\LogBundle\Entity\testChi $chiMTM) 
    { 
     if ($this->hasChiMTM($chiMTM)) { 
      $this->chiMTM->removeElement($chiMTM); 
     } 
    } 

    /** 
    * Add chiMTM 
    * 
    * @param \LogBundle\Entity\testChi $chiMTM 
    * 
    * @return ChiMTM 
    */ 
    public function addChiMTM(\LogBundle\Entity\testChi $chiMTM) 
    { 
     if (!$this->hasChiMTM($chiMTM)) { 
      $this->chiMTM[] = $chiMTM; 
     } 

     return $this; 
    } 

    /** 
    * @param \LogBundle\Entity\testChi $chiMTM 
    * @return bool 
    */ 
    public function hasChiMTM($chiMTM) 
    { 
     if($this->getChiMTM()) { 
      return $this->getChiMTM()->contains($chiMTM); 
     } 
    } 



    /** 
    * Return Entity as string 
    * 
    * @return string String representation of this class 
    */ 
    public function __toString() 
    { 
     return strval($this->id); 
    } 

} 

C:\ Bitnami \ wampstack-5.6.30-0 \的Apache2 \ htdocs中\ typejoy.biz> PHP廠商\教義\ ORM \ bin \ doctrine orm:schema-tool:create

創建兩個表,但不創建@JoinTable「tParChiMTM」。

回答

0

的原因是在註釋:

正確

/** 
* @ManyToMany (targetEntity="testPar", mappedBy="chiMTM") */ 

/** 
* @ManyToMany (targetEntity="testChi", inversedBy="parMTM") 
* (name="tParChiMTM") */ 
    private $chiMTM; 

你不能/**開始每行中,只有第一行應包含這一點,後續行只能與單*開始。

WRONG:

/** @ManyToMany (targetEntity="testChi", inversedBy="parMTM") */ 
/** @JoinTable (name="tParChiMTM") */