Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue with Remove Relation/set relation to null in Many to One relation #243

Open
coupster74 opened this issue Mar 30, 2024 · 0 comments
Open
Labels
bug Something isn't working

Comments

@coupster74
Copy link

coupster74 commented Mar 30, 2024

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:

event = await this.eventService.setRelation(
          'company',
          input.id,
          input.update.companyId,
        );

however, there is no convenient way to remove the relationship. I would think you could set it to null, but this does not work:

event = await this.eventService.setRelation(
          'company',
          input.id,
          null,
        );

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):

  • Node Version 18
  • Nestjs-query Version 5.1.0-alpha.1
@coupster74 coupster74 added the bug Something isn't working label Mar 30, 2024
@coupster74 coupster74 changed the title Remove Relation Issue with Remove Relation/set relation to null in Many to One relation Mar 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant