findQuery() is not working in ember-data?

Sachin

Fixture contain list of contacts and each contact has contact type. I am trying to filtrate contact records using .findQuery() but it is throwing following error :

Uncaught TypeError: Object function () {.....} has no method 'findQuery' 

I have listed my code here :

Grid.Store = DS.Store.extend({
                  revision: 12,
                  adapter: 'DS.FixtureAdapter'
            }); 

    Grid.ModalModel =  DS.Model.extend({
    fname: DS.attr('string'),
    lname: DS.attr('string'),
    email: DS.attr('string'),
    contactno: DS.attr('string'),
    gendertype: DS.attr('boolean'),
    contactype: DS.attr('number')
});

Grid.ModalModel.FIXTURES = [
                       {
                         id: 1,
                         fname: "sachin",
                         lname: "gh",
                         email: "gh",
                         contactno: "4542154",
                         gendertype: true,
                         contactype: 1
                       },
                       {
                         id: 2,
                         fname: "amit",
                         lname: "gh",
                         email: "gh",
                         contactno: "4542154",
                         gendertype: true,
                         contactype: 2
                       },
                       {
                         id: 3,
                         fname: "namit",
                         lname: "gh",
                         email: "gh",
                         contactno: "4542154",
                         gendertype: true,
                         contactype: 1
                       }
                      ];

Controller Code:

        totpersonalcontact:function(){ 
        return Grid.ModalModel.findQuery({ contactype: 2 }).get('length'); 
    }.property('@each.isLoaded'),
    totfriendcontact:function(){ 
        return Grid.ModalModel.findQuery({ contactype: 3 }).get('length'); 
    }.property('@each.isLoaded')

I have changed .findQuery to .query but every time it is showing length as 0.

Marcio Junior

Just change findQuery to query.

After this a error message will appear in console:

Assertion failed: Not implemented: You must override the DS.FixtureAdapter::queryFixtures method to support querying the fixture store. 

Like the message explain, just implement the DS.FixtureAdapter#queryFixtures. The parameters passed to queryFixtures is: records, query, type. Where:

  • Records is an array of plain javascript objects, that you will filter.
  • Query is the object passed to query method of your ember data class.
  • Type is the ember data class, where the query is call.

And the return is the filtered data.

For example, to perform a simple where like:

App.Person.query({ firstName: 'Tom' })

Just reopen your DS.FixtureAdapter with:

DS.FixtureAdapter.reopen({
    queryFixtures: function(records, query, type) {        
        return records.filter(function(record) {
            for(var key in query) {
                if (!query.hasOwnProperty(key)) { continue; }
                var value = query[key];
                if (record[key] !== value) { return false; }
            }
            return true;
        });
    }
});

Here is a live demo.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Ember component sendAction() not working

From Dev

Ember-Data custom adapter for Rhom - FindAll Not working

From Dev

ember not working on jsfiddle

From Dev

ember-data belongsTo not working

From Dev

Ember-data hasMany association not working

From Dev

ember data rest adapter not working

From Dev

Ember-data: working with model in controllers/views

From Dev

Emberjs / Ember-Data: Working with multiple REST Servers (hosts)?

From Dev

Ember Data DS.Store.filter() not working on nested routes?

From Dev

Simple Ember Route not working?

From Dev

Ember Data Model rollback not working on custom attribute of model

From Dev

Ember without Ember Data

From Dev

Ember data createRecord not working: "TypeError: undefined is not a function"

From Dev

Ember fixtures not working

From Dev

SetTimeout Not Working In Ember Controller?

From Dev

Ember Store suddenly not working

From Dev

Ember Assertion Failed: The response from a findQuery must be an Array, not undefined

From Dev

Ember data Rest adapter error handling not working

From Dev

Ember Data without Ember?

From Dev

Delete/Update record of model is not working in ember-data?

From Dev

Can't get simple ember-data working

From Dev

Ember-data: working with model in controllers/views

From Dev

Ember Data Model rollback not working on custom attribute of model

From Dev

Ember without Ember Data

From Dev

Models not working with the new Ember-data upgrade

From Dev

Ember Assertion Failed: The response from a findQuery must be an Array, not undefined

From Dev

Ember Data one to many relationship not working

From Dev

Ember data Rest adapter error handling not working

From Dev

Ember Data 1.13 findAll isn't working

Related Related

HotTag

Archive