I'm trying to create a optional OneToOne mapping in Doctrine.
I have a table with all cities and zip codes available (this table shouldn't be changed), and I have a table with addresses and a mapped city. But sometimes I don't want to add City to my Address at the beginning (maybe later on it will). But when I don't add a City to the Address the persist on the Address gives me a Reflection Exception because there is no object like 'null' , which should be de City object.
I don't want to add an empty city every time into the database, because there should nothing be added or deleted to the city table.
Any suggestions? Or what am I missing?
class Address{
/**
* @OneToOne(targetEntity="City")
* @JoinColumn(name="city_id", referencedColumnName="id")
*/
private $city = '';
Possible solutions I considered:
Just simply add nullable=true
to @JoinColumn
annotation
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With