PUT a property with object relation to null
See original GitHub issueSo I have an Person entity and a Country entity. The Person entity has this property
/**
* @var Country
*
* @ORM\ManyToOne(targetEntity="Country")
* @ORM\JoinColumns({
* @ORM\JoinColumn(name="countryOfNationalityId", referencedColumnName="id", nullable=true)
* })
* @Groups({"get_method", "put_method"})
*/
private $countryOfNationality;
The issue is that I can not make it NULL after it has been set already. So if I use PUT with {“countryOfNationality” : null}, I get this error: Expected argument of type \"App\\Entity\\Country\", \"NULL\" given at property path \"countryOfNationality\"."
Is there anyway to nullify a property with relation? Thanks.
Issue Analytics
- State:
- Created 5 years ago
- Comments:21 (7 by maintainers)
Top Results From Across the Web
Add property to object when it's not null - javascript
This works because Object.assign will skip over null parameters. If you are sure that the property value is not going to be "falsy", ......
Read more >How to set nullable/optional property of database object to ...
1 Answer 1 · Retrieve the object of type Foo with Id 65 from the database · Modify NullableProperty to set it to...
Read more >Set all Values in an Object to Null using JavaScript | bobbyhadz
To set all values in an object to null , pass the object to the Object.keys() method to get an array of the...
Read more >Working with nullable reference types - EF Core
DbContext and DbSet ... Another strategy is to use non-nullable auto-properties, but to initialize them to null, using the null-forgiving operator ...
Read more >Object.create() - JavaScript - MDN Web Docs
me.name = 'Matthew'; // "name" is a property set on "me", but not on "person" ... Thrown if proto is neither null nor...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

public function setCountryOfNationality(Country $countryOfNationality): selfbecomes …
public function setCountryOfNationality(?Country $countryOfNationality): selfand it should work.
@osamaarefm , @mrtnzagustin cc. @teohhanhui
I solved this issue via EventSubscriber, check it out:
I has some entities with property
coverwhich includes other entity. For those entities I’ve implement interface and add event subscriber: