ember-jsonapi-resources
ember-jsonapi-resources copied to clipboard
Initialize empty toOne relationships actually empty
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.
@andrewmp1 what do you think about initializing with null ?
This issue can also be resolved in the toOne-promise-aware PR (and/or the upcoming change on that one, using the proxy).