Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Embedded one-to-one relationships represented as `null` trips up ember #593

Closed
sandstrom opened this Issue · 2 comments

2 participants

@sandstrom

Embedded one-to-one relationships represented as null, instead of undefined (or omitted from the json payload) trips up ember.

This can (and probably should) be solved by the server-side serializer, but afaik the default for e.g. Active Model Serializers is to represent these as null.

Would it make sense for ember to handle null and undefined the same in this case (that would also solve the problem), or is there some drawback to that? For regular model fields the distinction between null and undefined can be important, but for embedded records I don't see a case where that should matter, though I may have overlooked something.

I hope this is clear enough, let me know if I should elaborate.

App.Mother = DS.Model.extend({
  name: attr('string')
  child: DS.belongsTo("App.Child")
});

App.Child = DS.Model.extend({
  voter: attr('string')
  mother: DS.belongsTo("App.Child")
});

Adapter.map("App.Mother", {
  child: { embedded: 'always' }
});

// will instantiate a child on the mother, but as soon as it's accessed an error is thrown
{
    "id": 1,
    "name": "mother",
    "child": null
}
// works just fine
{
    "id": 1,
    "name": "mother"
}
@ppcano

Try #564

@sandstrom

@ppcano I worked around it by using undefined instead of null, but thanks a lot for pointing me to the PR, I hadn't seen that.

Solved by #564, closing this issue.

@sandstrom sandstrom closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.