Access the store finder _findQuery in ember-cli

70 Views Asked by At

I need to override the DS.Store.findQuery in Ember cli. that is no problem in itself.

The problem is importing the _findQuery method from the 'finder' file -- in that new app/store.js file

this._findQuery doesnt work

https://github.com/emberjs/data/blob/master/packages/ember-data/lib/system/store.js

in the 'shimmed' component/ember-data the prototype is

function ember$data$lib$system$store$finders$$_findQuery(adapter, store, typeClass, query, recordArray

Has anyone some advice on the required import statement.

here is some failed attempts

import DS from 'ember-data';
import Ember from 'ember';

//import _findQuery from 'ember-data/lib/system/store/finders'; NOPE
//import _findQuery from 'ember-data'; NOPE

export default DS.Store.extend({

  findQuery: function(typeName, query) {
    var type = this.modelFor(typeName);
    var array = this.recordArrayManager
      .createAdapterPopulatedRecordArray(type, query);

    var adapter = this.adapterFor(type);

    Ember.assert("You tried to load a query but you have no adapter (for " + type + ")", adapter);
    Ember.assert("You tried to load a query but your adapter does not implement `findQuery`", typeof adapter.findQuery === 'function');

    var x = _findQuery(adapter, this, type, query, array); // <-- URGH HERE
    return promiseArray(x);
  },
1

There are 1 best solutions below

0
On

I'm not sure that you are able to import it in the way you describe, you could do it on the Adapter though.

You should be able to override it per Adapter, or if you want to do it everywhere, override on your application Adapter.

Like this

import DS from 'ember-data';
import Ember from 'ember';

export default DS.ActiveModelAdapter.extend({
  findQuery (typeName, query) {
    // do your stuff here
  }
});