Lazy Loading Ember-Data Queries

I’m trying to write an ember-data adapter for a custom API backend. It allows full-text search using a query, returning records from the store.

I implemented query(store, type, query) in my adapter, and it works fine, but only when I return the full model when resolving the promise. This might be thousands of objects, and I don’t want to display them all at once anyways. Is there a way to return incomplete objects here that get queried via findRecord once they’re actually needed?

I can return an array of {id:"..."} objects from there, but they just have all attributes set to undefined and are never fetched from the server. Their isLoaded flag is incorrect.

Manually calling reload() on all objects returned from that query does set the attributes correctly, but that’s not the point of using ember-data in the first place.

How can I modify the isLoaded flag for this?

To answer my own question, I found a nice workaround:

I created an intermediary model class that only contains an id and a belongsTo property to the real object (both using the same id). This way, the returned object is fully loaded, but once you try to access the belongsTo property, it is loaded asynchronously from the server. This is exactly what I want.