How to load proxy relationships in Ember testing

I am trying to test whether a model gets hydrated with the appropriate data, but I am getting proxy objects back in regards to relationship models (belongsTo, hasMany) instead of the model itself. I have tried creating the model with the data, “get”-ing the models after the fact, and creating new model instances, and then setting them on the model, but it always returns a proxy object.

Does anyone have any guidance on this issue? I saw another thread similar to this (Ember Data Proxy BelongsTo) but I wanted to see if there were any fresh ideas.

If the relationships are “async” (which they are by default) they will always return proxies. There are a few things you could do if you don’t want to deal with the proxies…

  • convert the relationships to synchronous (some would argue this should be the default) but this may require a broader rethinking of your data fetching patterns
  • “unwrap” it by waiting for it with await (async function, e.g. in a test like you want to do) or yield (ember concurrency task) e.g. await model.relationshipName
  • use the lower level relationship APIs to get the relationship value synchronously, e.g. model.belongsTo('relationshipName').value()
  • refer to the proxy content (i don’t really recommend this) e.g. model.relationshipName.content

Relevant pages from the docs:

Thank you for the quick reply! Unfortunately, only the last option worked so I am trying to go about it a different way.