문제

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?

Example:

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.

도움이 되었습니까?

해결책

You best bet it so manually insert 0 into user_id just before persisting in your controller.

$comment->setUserId(0);
$em->persist($comment);
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top