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

Empty record's relationships serialization and JSONAPI specs #5173

Closed
tomdrn opened this issue Sep 14, 2017 · 6 comments
Closed

Empty record's relationships serialization and JSONAPI specs #5173

tomdrn opened this issue Sep 14, 2017 · 6 comments
Labels
🏷️ feat This PR introduces a new feature

Comments

@tomdrn
Copy link

tomdrn commented Sep 14, 2017

Hi,

Some changes have been recently made on record's relationships serialization (see #5048)

As said, createRecord should only setup relationships with data, which sounds logic but it also causes some issues related to the JSONAPI specs.

As mentioned here : http://jsonapi.org/format/#document-resource-object-linkage

Resource linkage MUST be represented as one of the following:

  • null for empty to-one relationships.
  • an empty array ([]) for empty to-many relationships.
  • a single resource identifier object for non-empty to-one relationships.
  • an array of resource identifier objects for non-empty to-many relationships.

In result, my JSONAPI handler reject requests and is asking for relationships to be present in the payload, empty or not.

@hjdivad @stefanpenner @runspired @bmac Maybe I'm missing something, could you please clarify this ?

Thanks !

@tomdrn tomdrn changed the title Empty Record's relationships serialization and JSONAPI specs Empty record's relationships serialization and JSONAPI specs Sep 14, 2017
@fabriciotav
Copy link

It seems that now (since ember-data 2.14.4) you'll have to explicitly set the "empty" relationship. For instance:

// This will be serialized as you expect
const post = this.store.createRecord('post', {
  title: 'Lorem ipsum',
  comments: []
});

post.save();
// This will **not** be serialized as you expect
const post = this.store.createRecord('post', {
  title: 'Lorem ipsum'
});

post.set('comments', []);
post.save();

@runspired
Copy link
Contributor

@fabriciotav thanks for the clear delineation. I should be able to address this rather easily in #5410

@runspired
Copy link
Contributor

I suspect this and #5100 are manifestations of the same issue.

@runspired
Copy link
Contributor

This was likely related but I don't think it was the root cause: #5466

@runspired
Copy link
Contributor

A number of fixes were landed to ensure we always serialize as much as we should, if more are needed please open a new ticket. That said, for most situations the answer is to customize the serialization to fit your API.

@runspired runspired added 🏷️ feat This PR introduces a new feature and removed Improvement labels Sep 11, 2023
@a1723
Copy link

a1723 commented Oct 31, 2023

It seems that now (since ember-data 2.14.4) you'll have to explicitly set the "empty" relationship. For instance:

// This will be serialized as you expect
const post = this.store.createRecord('post', {
  title: 'Lorem ipsum',
  comments: []
});

post.save();
// This will **not** be serialized as you expect
const post = this.store.createRecord('post', {
  title: 'Lorem ipsum'
});

post.set('comments', []);
post.save();

thanks, it helps me to resolve warning.
Ember 5.3.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🏷️ feat This PR introduces a new feature
Projects
None yet
Development

No branches or pull requests

4 participants