and for some reason, removeRelation still requires the ID to be removed, which while that makes sense if the relationshp was many to many and I was plucking on out of a collection, in a many to one, we are just trying to clear the single value, so removeRelation should not need a relationId.
Consider the following, simple, clean code:
if ('companyId' in inputEvent) {
event = await this.eventService.setRelation(
'company',
event.id,
inputEvent.companyId,
);
}
if setRelation supported a null companyId to clear the relationship, this is all I'd need to support setting and removing the relationship.
so.. options:
setRelation - could take a null for relationId and remove the relationship (similar in nature to the collection approach where you can just set the new collection).
removeRelation - remove the relationId parameter and just remove whatever relationship may exist
Desktop (please complete the following information):
Describe the bug QueryService setRelation and removeRelation don't work as expected for ManyToOne relationships.
Have you read the Contributing Guidelines?
yes
To Reproduce if you have a many to one relation on an entity, you can set it via code like this:
however, there is no convenient way to remove the relationship. I would think you could set it to null, but this does not work:
and for some reason,
removeRelation
still requires the ID to be removed, which while that makes sense if the relationshp was many to many and I was plucking on out of a collection, in a many to one, we are just trying to clear the single value, so removeRelation should not need arelationId
.Consider the following, simple, clean code:
if setRelation supported a null companyId to clear the relationship, this is all I'd need to support setting and removing the relationship.
so.. options: setRelation - could take a null for relationId and remove the relationship (similar in nature to the collection approach where you can just set the new collection). removeRelation - remove the relationId parameter and just remove whatever relationship may exist
Desktop (please complete the following information):