Reputation: 2759
In a legacy system we have a database that saves non existent relations with 0 instead of null. How can I get doctrine to save the parent row with 0 in the related column instead of null?
Comment-Table
------------------------------------
| id | user_id | comment |
------------------------------------
| 1 null this is a comment |
| 2 1 another comment |
------------------------------------
If I have an entity for that comment table I want it to save user_id = 0 in row 1 if there is no user for this comment. How can I achieve this?
Please consider, that I need this for a legacy system and changing the database schema so that null in that column is possible is no option.
Upvotes: 0
Views: 224
Reputation: 3656
You best bet it so manually insert 0 into user_id just before persisting in your controller.
$comment->setUserId(0);
$em->persist($comment);
Upvotes: 2