我試圖在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
通常這是當人們使用錯誤引號'可空=「真」'但是我看這不是這裏的情況...你不需要'@ var'或者'@ORM \ Column'來轉儲它們,看看是否有幫助? – Egg
謝謝@Egg。確實'@ORM \ Column'重寫了'@ JoinColumn',導致我所有的問題! –
不要忘記允許你的setter接受null:setVragenlijst($ vragenlijst = null) – LBA