Reputation: 2104
I'm trying to create Many to Zero or One link in a Symfony/Doctrine entity. I think the following should work the trick:
/**
* @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;
However: Doctrine seems to disagree with me:
[bhillier@devserver-2 Symfony]$ php app/console doctrine:schema:update --dump-sql
ALTER TABLE walkthrough CHANGE vragenlijst_id vragenlijst_id INT NOT NULL;
I'm probably missing something stupid, but I can't see what at the moment. Has anyone got any ideas?
In case it helps:
[bhillier@devserver-2 Symfony]$ /usr/local/apache2/bin/apachectl -version
Server version: Apache/2.4.18 (Unix)
Server built: Jan 26 2016 06:31:19
[bhillier@devserver-2 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
[bhillier@devserver-2 Symfony]$ php app/console --version
Symfony version 2.6.13 - app/dev/debug
Upvotes: 1
Views: 480
Reputation: 4397
According to your annotations, you're telling Doctrine
to create a column called vragenlijst_id
and you don't say anything about it's nullable attribute. You're doing so with the annotation:
@ORM\Column(name="vragenlijst_id")
The right annotations would be:
/**
* @var integer
*
* @ORM\ManyToOne(targetEntity="GroNed\AdminBundle\Entity\WalkthroughType")
*/
private $vragenlijst;
Upvotes: 2
Reputation: 1769
You will need to delete the @var
and @ORM\Column
annotations, these aren't required when using associations.
Upvotes: 2