ember-jsonapi-resources icon indicating copy to clipboard operation
ember-jsonapi-resources copied to clipboard

Initialize empty toOne relationships actually empty

Open aars opened this issue 8 years ago • 2 comments

ObjectProxys for toOne relationships were initialised with a fresh Ember.Object.create() as their content. Because of this, you can not do this:

if (resource.get('some-to-one-relationship')) { ... } or {{#if resource.some-to-one-relationship}} ... {{/if}}

resource.get('some-to-one-relationship.content') would not work either. You'd have to go look for attributes:resource.get('some-to-one-relationship.id'). But that doesn't work either, since there isn't really an attribute that should always be set... Maybe type, but that's just a hack.

By initialising with something falsy like null, we're all good.

aars avatar Mar 07 '17 09:03 aars

@andrewmp1 what do you think about initializing with null ?

pixelhandler avatar Mar 17 '17 16:03 pixelhandler

This issue can also be resolved in the toOne-promise-aware PR (and/or the upcoming change on that one, using the proxy).

aars avatar Mar 20 '17 08:03 aars