ember.js - queryFixtures always returns 0 results -
i implemented queryfixtures in fixtureadapter able make "more complex" queries. did (it's coffeescript):
app.store = ds.store.extend { revision: 13 adapter: ds.fixtureadapter.extend { queryfixtures: (fixtures, query, type) -> console.log fixtures.get('length') # 2 fixtures = fixtures.filter (item) -> prop of query if item[prop] != query[prop] return false return true console.log fixtures.get('length') # 1 return fixtures } }
here profile model + fixtures:
app.profile = ds.model.extend { name: ds.attr('string') businessname: ds.attr('string') picture: ds.attr('string') isbusiness: ds.attr('boolean') conversations: ds.hasmany('app.conversation') } app.profile.fixtures = [ { id: 1 name: 'jon snow' picture: 'https://encrypted-tbn3.gstatic.com/images?q=tbn:and9gcrdmu58eceoiuusmnpcewwv4qap4ft1fxxnk5axk15i6gsaiblc5rl50zuogqsdoedxbfe' isbusiness: false conversations: [101, 102] } { id: 2 name: 'jaime lannister' picture: 'https://encrypted-tbn0.gstatic.com/images?q=tbn:and9gcqb_k_ifak-da-tbwgom1nogxsc7qpvlaxaet76d8sdmoxad1c2wcvnskim8-sgfpmippq' isbusiness: true businessname: 'westeros inc.' conversations: [103] } ]
for testing purposes, make query on profile in init method of applicationroute:
app.applicationroute = ember.route.extend { init: -> profiles = app.profile.find { isbusiness: false } console.log profiles.get('length') # 0 ?? model: -> return app.profile.find() }
as see, logged fixtures.get('length') @ different places.
the first console.log in adapter returns "2" total amout of profiles (ok). second console.log in adapter returns "1" means filter working (ok). don't understand why third console.log in router return "0". it's data not returned correctly...
i'm not sure if i'm doing wrong, if it's bug in ember data, or if it's expected behavior. ideas?
fyi, here ember configuration:
ember.version : 1.0.0-rc.6 handlebars.version : 1.0.0-rc.4 jquery.version : 2.0.3
the console.log outputs length 0 because fixtureadapter simulating asynchronous query. log query result size console, use then
like:
app.applicationroute = ember.route.extend { init: -> profiles = app.profile.find { isbusiness: false } profiles.then (data) -> console.log 'count: ', data.get('length') # 1 model: -> return app.profile.find() }
jsbin here: http://jsbin.com/utasuh/1/edit
Comments
Post a Comment