PSA: Working With Model Relationships


When working with model relationships remember that they may be lazy, and even though getting and setting properties on a proxy object work as if you’re using the entity directly, things like comparison between entities (e.g. when using addons such as ember-truth-helpers) may not behave as you would expect.

Always resolve the promise obtained from accessing a relationship before doing any sort of comparison between entities e.g. this.get('model.relationship').then(relationship => {}).

When passing values into a component, you can ensure you’re working with the underlying object by using the didReceiveAttrs hook and wrapping getAttr in a promise e.g. Promise(this.getAttr('attribute')).then(attribute => this.set('attr1', attribute)).