lundi 19 août 2019

How to get relationship model from relationship of another model

I have some models with relationships, that are fething from firebase through emberfire:

library:

export default Model.extend({
  title: attr('string'),
  address: attr('string'),
  phone: attr('string'),
  books: hasMany('book')
});

book:

export default Model.extend({
  title: attr('string'),
  description: attr('string'),
  author: belongsTo('author'),
  libraries: hasMany('library')
});

author:

export default Model.extend({
  name: attr('string'),
  books: hasMany('book')
});

how can i fetch all the libraries of some author's books?

I already tried to fetch children's model after fetching parent one, but seems like promises return instances of not Model's class, and there is no relations fields i expected :/

 async model() {
    const authors = await this.store.findAll('author')
    const books = await Promise.all(authors.getEach('books'))
    const libraries = await Promise.all(books.getEach('libraries'))
    // libraries variable is undefined, cause books has no 'libraries' property
    return authors
  }




Aucun commentaire:

Enregistrer un commentaire