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

You can't fully delete relationships #4332

Closed
dortamiguel opened this issue May 26, 2017 · 6 comments · Fixed by #4667
Closed

You can't fully delete relationships #4332

dortamiguel opened this issue May 26, 2017 · 6 comments · Fixed by #4667
Assignees
Milestone

Comments

@dortamiguel
Copy link

I'm on the last commit on master but also this bug is present o the latest beta.

When you have a relationship you can't delete, it just ignore's it.

On a one to may relationship you can delete all of them except the last one.

@Noviny
Copy link
Contributor

Noviny commented Sep 29, 2017

Can you provide a replication case? We have not encountered this bug and use relationships extensively.

@jacobvr
Copy link

jacobvr commented Oct 4, 2017

Same issue. @Noviny here's the case:

Regular Relationship field in KeystoneJS (categories in this example):

Post.add({
    author: { type: Types.Relationship, ref: 'User' },
    categories: { type: Types.Relationship, ref: 'PostCategory', many: true }
});

Initially it's empty, but when I add some value to it, save it and then clear it (so that field is empty again), saving this Model won't update categories.

console.log(this.categories) in Post.schema.pre('save', ... shows that this.categories has previous value, while it should be empty.

Any ideas on this behavior?

@ryan-haskell
Copy link

Hey there,

Installing Keystone v4.0.0-beta.5 fixed this bug for me.

It looks like the v4.0.0-beta.8 version has this issue for both:

  • Single Relationship Fields
  • Many Relationship Fields

As a temporary workaround, I would stick to an earlier beta version like v4.0.0-beta.5

Good luck!
Ryan

@Twansparant
Copy link

Is there a workaround for v4.0.0-beta.8 without editing the keystone/fields/types/relationship/RelationshipType.js core file?

@stennie stennie changed the title You can't delete relationships You can't fully delete relationships May 27, 2018
@stennie stennie added this to the 4.0.0 milestone May 31, 2018
@stennie stennie self-assigned this Jun 2, 2018
@stennie
Copy link
Contributor

stennie commented Jun 2, 2018

@Noviny Looks like this bug was introduced with commit 5df6846: when all relationships are removed there will be no references in the data object.

Should this commit be reverted or is there some other context for the change?

@autoboxer autoboxer removed the 4.0 label Jun 2, 2018
@Noviny
Copy link
Contributor

Noviny commented Jun 12, 2018

The context for the change is that the relationship field being absent from a submission (undefined) should not automatically delete it.

This was causing a bug when calling update where the field was absent it would get deleted unintentionally.

It should definitely be valid to pass no data for a field when saving and not erase it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment