2016-02-12 45 views
1

我試圖在Symfony/Doctrine實體中創建Many to Zero或One鏈接。我認爲有以下應該工作的伎倆:我不能使一個JoinColumn爲空

/** 
* @var integer 
* 
* @ORM\Column(name="vragenlijst_id") 
* @ORM\ManyToOne(targetEntity="GroNed\AdminBundle\Entity\WalkthroughType") 
* @ORM\JoinColumn(name="vragenlijst_id", referencedColumnName="id", nullable=true) 
*/ 
private $vragenlijst; 

但是:教義似乎與我不同意:

[[email protected] Symfony]$ php app/console doctrine:schema:update --dump-sql 
ALTER TABLE walkthrough CHANGE vragenlijst_id vragenlijst_id INT NOT NULL; 

我可能失去了一些東西愚蠢,但我看不到有什麼,此刻。有沒有人有任何想法?

在情況下,它可以幫助:

[[email protected] Symfony]$ /usr/local/apache2/bin/apachectl -version 
Server version: Apache/2.4.18 (Unix) 
Server built: Jan 26 2016 06:31:19 
[[email protected] Symfony]$ /opt/php-5.6/bin/php --version 
PHP 5.6.17 (cli) (built: Jan 26 2016 05:36:55) 
Copyright (c) 1997-2015 The PHP Group 
Zend Engine v2.6.0, Copyright (c) 1998-2015 Zend Technologies 
[[email protected] Symfony]$ php app/console --version 
Symfony version 2.6.13 - app/dev/debug 
+1

通常這是當人們使用錯誤引號'可空=「真」'但是我看這不是這裏的情況...你不需要'@ var'或者'@ORM \ Column'來轉儲它們,看看是否有幫助? – Egg

+0

謝謝@Egg。確實'@ORM \ Column'重寫了'@ JoinColumn',導致我所有的問題! –

+1

不要忘記允許你的setter接受null:setVragenlijst($ vragenlijst = null) – LBA

回答

2

你將需要刪除@var@ORM\Column註解,這些未使用的關聯時需要。

2

根據你的註釋,你告訴Doctrine創建一個名爲vragenlijst_id的列,並且你不會說關於它的可空屬性的任何內容。你與註釋這樣做:

@ORM\Column(name="vragenlijst_id") 

正確的註釋是:

/** 
    * @var integer 
    * 
    * @ORM\ManyToOne(targetEntity="GroNed\AdminBundle\Entity\WalkthroughType") 
    */ 
    private $vragenlijst; 
+0

嗨,奧斯卡!你和Egg的回答都是正確的,但是@Egg已經在我的評論中把我放在了正確的軌道上,所以我已經將他的答案記入了他。謝謝你的幫助。 –

+0

@BenHillier:很高興有幫助! –

相關問題