I have two models defined in Ember and also in a Rails application:
App.Library = DS.Model.create({
books: DS.hasMany('App.Book')
});
App.Book = DS.Model.create({
library: DS.belongsTo('App.Library')
});
On the back-end side, I have several Book for each Library, I would like to retrieve those books but there is no back-end call when I do this (library object is correct and has an id that match its id on the back-end):
var libraryBooks = library.get("books");
I am expecting a back-end call to my rails API in order to fetch all books for this specific library, but instead I just get the empty Ember.OrderedSet without back-end call.
I am starting with Ember so maybe this is not correct, if this is the case, what is the best way to retrieve the “hasmany” for a given model directly from the back-end if you only have the model’s id?
.find()will make ember do a request.it’ll to a request to
/librarys/1i think. You can configure the plural like this:Now the request will be to
/libraries/1You could also probably get the books by the library:
the
library: 1you’ll have to handle yourself on the backend. emberdata sends it as a querystring. Like this:/books?library=1Have a look here there is some documentation on ember-data