Quantcast
Viewing all articles
Browse latest Browse all 4827

Best way to sort array by async relationship attribute?

@konrad wrote:

Lets say I have three models:
- A: contains items property which is a hasMany relationship to B
- B: contains details property which is a belongsTo relationship to an instance of C
- C: contains property name which I want to be my sort key

// app/models/a.js
import DS from 'ember-data';
const { hasMany } = DS;

export default DS.Model.extend({
  items: hasMany('b', { async: true })
});

.

// app/models/b.js
import DS from 'ember-data';
const { belongsTo } = DS;

export default DS.Model.extend({
  details: belongsTo('c', { async: true })
});

.

// app/models/c.js
import DS from 'ember-data';
const { attr } = DS;

export default DS.Model.extend({
  name: attr('string')
});

Question: What is the best way to sort the items array in model A by details.name property?

Posts: 1

Participants: 1

Read full topic


Viewing all articles
Browse latest Browse all 4827

Trending Articles