Skip to content

Commit

Permalink
[BUGFIX query] Remove arity check for adapter.query (emberjs#6250)
Browse files Browse the repository at this point in the history
This addresses the issue described in emberjs#6232. The arity check that decides whether to create a record array and pass options to adapter.query fails when the adapter extends EmberObject.
  • Loading branch information
loganrosen authored and pliljegr committed Jul 23, 2019
1 parent a408eaa commit da4cf35
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ module('integration/record-arrays/adapter_populated_record_array - DS.AdapterPop
);
});

test('pass record array to adapter.query based on arity', function(assert) {
test('pass record array to adapter.query regardless of arity', function(assert) {
let env = setupStore({ person: Person });
let store = env.store;

Expand All @@ -175,7 +175,8 @@ module('integration/record-arrays/adapter_populated_record_array - DS.AdapterPop
};

env.adapter.query = function(store, type, query) {
assert.equal(arguments.length, 3);
// Due to #6232, we now expect 5 arguments regardless of arity
assert.equal(arguments.length, 5);
return payload;
};

Expand All @@ -188,7 +189,7 @@ module('integration/record-arrays/adapter_populated_record_array - DS.AdapterPop
});
});

test('pass record array to adapter.query based on arity', function(assert) {
test('pass record array to adapter.query regardless of arity', function(assert) {
let env = setupStore({ person: Person });
let store = env.store;

Expand All @@ -214,7 +215,8 @@ module('integration/record-arrays/adapter_populated_record_array - DS.AdapterPop
};

env.adapter.query = function(store, type, query) {
assert.equal(arguments.length, 3);
// Due to #6232, we now expect 5 arguments regardless of arity
assert.equal(arguments.length, 5);
return payload;
};

Expand Down
12 changes: 2 additions & 10 deletions packages/store/addon/-private/system/store/finders.js
Original file line number Diff line number Diff line change
Expand Up @@ -337,16 +337,8 @@ export function _findAll(adapter, store, modelName, options) {
export function _query(adapter, store, modelName, query, recordArray, options) {
let modelClass = store.modelFor(modelName); // adapter.query needs the class

let promise;
let createRecordArray =
adapter.query.length > 3 || (adapter.query.wrappedFunction && adapter.query.wrappedFunction.length > 3);

if (createRecordArray) {
recordArray = recordArray || store.recordArrayManager.createAdapterPopulatedRecordArray(modelName, query);
promise = Promise.resolve().then(() => adapter.query(store, modelClass, query, recordArray, options));
} else {
promise = Promise.resolve().then(() => adapter.query(store, modelClass, query));
}
recordArray = recordArray || store.recordArrayManager.createAdapterPopulatedRecordArray(modelName, query);
let promise = Promise.resolve().then(() => adapter.query(store, modelClass, query, recordArray, options));

let label = `DS: Handle Adapter#query of ${modelName}`;
promise = guardDestroyedStore(promise, store, label);
Expand Down

0 comments on commit da4cf35

Please sign in to comment.