-
Notifications
You must be signed in to change notification settings - Fork 23
Retrieving
The most simple query is to retrieve all objects of a certain kind.
Artist.get()Because this is not a database query but an API query, results of multiple objects are always paginated. Artist.get() retrieves the first page. Other pages are retrieved like this:
Artist.get(3)...which retrieves the third page. The default page size of the underlying API can be overridden; how this is done is explained here.
A single object can be retrieved either by ID
Artist.find(123)Which can also be a string
Artist.find('tomaskalnoky')Or a single object is retrieved by taking only the first result of some query
Artist.first()A filter can be applied on a property of the object you are trying to retrieve.
Artist
.where('gender', 'm')
.get()From the response object, queried objects can be retrieved like this.
Artist
.get()
.then(function (PluralResponse response) {
let artists: Artist[] = response.getData();
});One can also directly access included models with getIncluded() as follows follows
Artist
.get()
.include('albums')
.then(function (PluralResponse response) {
let albums: Album[] = response.getIncluded();
});Note that getIncluded() returns all included models, even when there are multiple includes. So in
Artist
.get()
.include('albums.songs')
.then(function (PluralResponse response) {
let albumsAndSongs: Model[] = response.getIncluded();
});the array albumsAndSongs contains both Album and Song objects.