@onsmith wrote:
I have a large one-to-many relationship modeled by ember-data
hasMany
.// models/parent.js export default DS.Model.extend({ children: DS.hasMany('child'), // may have hundreds of children });
// models/child.js export default DS.Model.extend({ parent: DS.belongsTo('parent'), });
Since a
parent
has so manychildren
, I do not want to resolve the relationship all at once.// Avoid this, since it resolves all the children at once const childrenPromise = parent.get('children');
Instead, I’m implementing pagination. As far as I’ve seen, there is currently no built-in pagination for ember-data. So I’m implementing a custom solution, using the opaque
query()
adapter method and passing in the relevant paging information.Here’s my question: For a given
parent
record, I need access to an array of allchildren
currently loaded in the client-side store – without resolving the relationship. Furthermore, I need the array to update automatically as records in the store are changed, added, or removed.Is there an easy way to do this? If not, what will it take to make it happen?
Could I use the ds-references functionality to achieve this without forcing the relationship to resolve? If so, is there a clean way to put the necessary code in the
parent
model, so I can simply query a property of theparent
record and be given a live-updating array of related records?
Posts: 1
Participants: 1