Skip to content

queryFixtures adapter always return false after several queries (1.0.0-beta.2) #1269

Closed
lauhub opened this Issue Sep 10, 2013 · 6 comments

4 participants

@lauhub
lauhub commented Sep 10, 2013

When defining a FixtureAdapter, the queryFixtures function is correctly called at the first time.

var places = this.store.find('place', {site:siteId});
//Returns a populated array on first call
//Returns an empty array on next calls

But after another call, it does not work anymore. The only way to fix this is to reload the page.

See http://jsbin.com/epAnErA/17/

Go to Display menu.
Select Site
Select a site, the select a record
Go to Display menu again
Select a site.
Places table is empty (it should not).

This bug was already described here (issue 1177) but I open a separated issue for more clarity.

@wycats
Ember.js member
wycats commented Sep 11, 2013

In this example, I don't see any queries, nor an implementation of queryFixtures (which isn't provided by the default implementation).

What am I missing?

@lauhub
lauhub commented Sep 11, 2013

Sorry, I did not put the queryFixtures function I used in my first post.

And what I call query is the this.store.find(...) (but may be I am wrong by calling this 'query').

Actually if you check the jsbin, you'll have the full example. Should I provide more information ?

@wycats
Ember.js member
wycats commented Sep 12, 2013

You're calling this.store.find('post', id), which is a request for an individual record. I don't see any queries using a syntax like this.store.find('post', { query... }). What am I missing?

@lauhub
lauhub commented Sep 12, 2013

In the SiteRoute.setupController:

    var places = this.store.find('place', {site:siteId});

In the SitePlaceRoute.setupController:

    var records = this.store.find('record', {place:placeId});
This was referenced Sep 29, 2013
@genkgo
genkgo commented Apr 9, 2014
App.Store = DS.Store.extend({
    revision : 13,
    adapter : DS.FixtureAdapter.extend({
        queryFixtures : function(fixtures, query, type) {
            return fixtures.filter(function(item) {
                for (prop in query) {
                    var intValue = parseInt(query[prop]);
                    if (item[prop] instanceof Array) {
                        var result = false;
                        item[prop].forEach(function(element) {
                            if (typeof element === 'number') {
                                if (intValue == element) {
                                    result = true;
                                }
                            } else {
                                if (element.id == intValue) {
                                    result = true;
                                }
                            }
                        });
                        return result;
                    } else {
                        return (item[prop] != query[prop]);
                    }
                }
                return true;
            });
        }
    })
});

Should solve this issue.

@igorT
Ember.js member
igorT commented May 28, 2014

The code sample is for a very old version of ED. Please reopen the issue if this is still a problem for you. I tried running the attached jsbin but couldn't get it to work with the latest version of ED.

@igorT igorT closed this May 28, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.