11import DS from 'ember-data' ;
22import { camelize } from '@ember/string' ;
33import { isEmpty } from '@ember/utils' ;
4+ import { appendToQueryParam } from 'ember-data-utils/utils/url' ;
5+ import { getOwner } from '@ember/application' ;
46
57/**
6- Class to set as your ApplicationAdapter. Extend it for each model
7- you want to configure explicit filter and include params.
8-
8+ Class to set as your ApplicationAdapter. Extend it for each model
9+ you want to configure explicit filter and include params.
10+
911 ```js
1012 // app/adapters/application.js
1113 import { EmberDataUtilsJSONAPIAdapter } from 'ember-data-utils';
@@ -26,20 +28,20 @@ import { isEmpty } from '@ember/utils';
2628 */
2729export default DS . JSONAPIAdapter . extend ( {
2830 /**
29- List of query param keys that your resource supports filtering on.
30- Extend your base class for specific models to declare.
31+ List of query param keys that your resource supports filtering on.
32+ Extend your base class for specific models to declare.
3133 @field {Array} supportedFilters
3234 */
3335 supportedFilters : [ ] , // eslint-disable-line ember/avoid-leaking-state-in-ember-objects
3436
3537 /**
3638 Array of includes to always include when querying a particular model.
37- Extend your base class for specific models to declare.
38-
39+ Extend your base class for specific models to declare.
40+
3941 @field {Array} include
4042 */
4143 include : [ ] , // eslint-disable-line ember/avoid-leaking-state-in-ember-objects
42-
44+
4345 /**
4446 * @public
4547 * @method query
@@ -60,9 +62,9 @@ export default DS.JSONAPIAdapter.extend({
6062 * queryRecord and findRecord use buildQuery to add includes to
6163 * api calls. This override adds an adapters configured set of
6264 * default includes
63- *
65+ *
6466 * @method buildQuery
65- * @param {object } snapshot
67+ * @param {object } snapshot
6668 * @return {object } Mutated query object
6769 */
6870 buildQuery ( snapshot ) {
@@ -77,20 +79,30 @@ export default DS.JSONAPIAdapter.extend({
7779 let combinedUniqueIncludes = [ ...new Set ( existingIncludes . concat ( include ) ) ] ;
7880
7981 query . include = combinedUniqueIncludes . join ( ',' ) ;
80-
82+
8183 return query ;
8284 } ,
8385
86+ findHasMany ( store , snapshot , url , relationship ) {
87+ let adapter = this . _adapterForRelationship ( relationship . type ) ;
88+ let updatedUrl = appendToQueryParam ( url , 'include' , adapter . include )
89+ return this . _super ( store , snapshot , updatedUrl , relationship ) ;
90+ } ,
91+
92+ _adapterForRelationship ( type ) {
93+ return getOwner ( this ) . lookup ( `adapter:${ type } ` ) ;
94+ } ,
95+
8496 /**
8597 * Mutate the `jsonApiQueryParams` object with pagination related keys from `rawQueryParams` object
86- *
98+ *
8799 * Pagination related keys are `limit`, `since`, and `until`
88- *
100+ *
89101 * @private
90102 * @method _applyPagination
91103 * @param {Object } jsonApiQueryParams Object of JSONAPI formated query params
92104 * @param {Object } rawQueryParams Original, unformated Object of query params
93- * @return {Object } Mutated jsonApiQueryParams object with pagination params applied
105+ * @return {Object } Mutated jsonApiQueryParams object with pagination params applied
94106 */
95107 _applyPagination ( jsonApiQueryParams , rawQueryParams ) {
96108 [ 'limit' , 'since' , 'until' ] . forEach ( key => {
0 commit comments