2016-02-04 104 views
0

我想學習框架學說2.我在MySQL中有一個模型並在Doctrine中實現它。在兩個類「任務」和「下拉列表」之間實現依賴關係後,它不起作用。學說2問題

我的代碼是:

<?php 
use Doctrine\Common\Collections; 
use Doctrine\ORM\Mapping AS ORM; 

/** 
* Task 
* 
* @Table(name="task") 
* @Entity 
*/ 
class Task 
{ 
    /** 
    * @var integer 
    * 
    * @Column(name="ID", type="integer", nullable=false) 
    * @Id 
    * @GeneratedValue(strategy="IDENTITY") 
    */ 
    private $id; 

    /** 
    * @var Dropdownlist 
    * @ORM\OneToMany(targetEntity="Dropdownlist", mappedBy="tasks") 
    * @ORM\JoinColumn(name="priority", referencedColumnName="id") 
    */ 
    protected $priority; 

    /** 
    * @var string 
    * 
    * @Column(name="Label", type="string", length=45, nullable=true) 
    */ 
    private $label; 



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

    /** 
    * Set priority 
    * 
    * @param integer $priority 
    * 
    * @return Task 
    */ 
    public function setPriority($priority) 
    { 
     $this->priority = $priority; 
     return $this; 
    } 

    /** 
    * Get priority 
    * 
    * @return integer 
    */ 
    public function getPriority() 
    { 
     return $this->priority; 
    } 

    /** 
    * Set label 
    * 
    * @param string $label 
    * 
    * @return Task 
    */ 
    public function setLabel($label) 
    { 
     $this->label = $label; 

     return $this; 
    } 

    /** 
    * Get label 
    * 
    * @return string 
    */ 
    public function getLabel() 
    { 
     return $this->label; 
    } 
} 



/** 
* Dropdownlist 
* 
* @Table(name="dropdownlist") 
* @Entity 
*/ 
class Dropdownlist 
{ 
    /** 
    * @var integer 
    * 
    * @Column(name="ID", type="integer") 
    * @Id 
    * @GeneratedValue(strategy="IDENTITY") 
    */ 
    private $id; 

    /** 
    * @var string 
    * 
    * @Column(name="PriorityLabel", type="string", length=45, nullable=true) 
    */ 
    private $prioritylabel; 


    /* 
    * @var ArrayCollection 
    * @ORM\ManyToOne(targetEntity="Task", inversedBy="priority") 
    */ 
    protected $tasks; 


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

    /** 
    * Set prioritylabel 
    * 
    * @param string $prioritylabel 
    * 
    * @return Dropdownlist 
    */ 
    public function setPrioritylabel($prioritylabel) 
    { 
     $this->prioritylabel = $prioritylabel; 

     return $this; 
    } 

    /** 
    * Get prioritylabel 
    * 
    * @return string 
    */ 
    public function getPrioritylabel() 
    { 
     return $this->prioritylabel; 
    } 

    public function getTasts(){ 
     return $this->tasks; 
    } 

    public function __construct() 
    { 
    } 
} 

問題:

數據庫模式是不符合當前的映射文件同步。 是什麼原因? 問題在哪裏?

致以問候

回答

0

這意味着您的數據庫與您當前的映射不同步。 運行doctrine:schema:update --complete --dump-sql以查看需要完成哪些更改。您也可以運行doctrine:schema:update --complete --force直接部署更改。

+0

Hallo,結果:ALTER TABLE任務DROP優先級; 但這不是原因。我需要列優先級 – user3452883

+0

您是否想要將'Task#$ priority'映射爲'ManyToOne'? 'OneToMany'沒有關聯列,因此'JoinColumn'被忽略。 – Ocramius

+0

如果我在評論之前使用@ORM,它不起作用,爲什麼? 沒有它的作品。但是對於註解,我需要這個ORM。 – user3452883