Trouble getting Fixture Adapter working with Ember App Kit


#1

I’m having some trouble accessing the store for a DS.FixtureAdapter using Ember App Kit.

My app/adapters/application.coffee

ApplicationAdapter = DS.FixtureAdapter.extend
`export default ApplicationAdapter`

My models/question.coffee

  Question = DS.Model.extend
  title: DS.attr 'string'
  question: DS.attr 'string'
  date: DS.attr 'date'
  author: DS.attr 'string'

Question.reopenClass
  FIXTURES: [
    {
      id:        101,
      title:    'How do I feed hamsters?',
      author:   'Tom Dale',
      date:     '2013-01-01T12:00:00',
      question: 'Tomster cant eat using knife and a fork because his hands are \
                 too small. We are looking for a way to feed him. Any ideas?'
    },
    {
      id:        102,
      title:    'Are humans insane?',
      author:   'Tomster the Hamster',
      date:     '2013-02-02T12:00:00',
      question: 'I mean are totaly nuts? Is there any hope left for them? Should \
                 we hamsters try to save them?'
    }
  ]

`export default Question`

My app/routes/questions/index.coffee

QuestionIndexRoute = Ember.Route.extend
      model: ->
        @.store.findAll('question')

`export default QuestionIndexRoute`

Now every time I try to load the page it errors out with TypeError: undefined is not a function

In Chrome checking the Ember Inspector Data tab, there isn’t any data. Even if I comment out the @.store.findAll('question') I still wouldn’t see anything.

Been pulling my hair out over this for awhile. Anybody got any suggestions?


#2

Any success with @store.find('question')

If not, can you try this:

Question = DS.Model.extend
  title: DS.attr 'string'
  question: DS.attr 'string'
  date: DS.attr 'date'
  author: DS.attr 'string'

Question.FIXTURES = [
  {
    id:       101
    title:    'How do I feed hamsters?'
    author:   'Tom Dale'
    date:     '2013-01-01T12:00:00'
    question: 'Tomster cant eat using knife and a fork because his hands are
               too small. We are looking for a way to feed him. Any ideas?'
  },
  {
    id:       102
    title:    'Are humans insane?'
    author:   'Tomster the Hamster'
    date:     '2013-02-02T12:00:00'
    question: 'I mean are totaly nuts? Is there any hope left for them? Should
               we hamsters try to save them?'
  }
]

`export default Question`

Not sure if it’s your preference or not, but figure I’d mention in CS you don’t need to append a . between @ and method. You can always do @method for this.method.


#3

I’ve tried using @store.find('question') and had the same issue. I’ve tried this.store.find('question') with the same results.

I went ahead and updated my Question model fixture like you suggested, but still having the same problem. Here’s the full stack trace from the problem:

TypeError: undefined is not a function
    at instantiate (http://localhost:8000/vendor/ember/ember.js:11333:26)
    at lookup (http://localhost:8000/vendor/ember/ember.js:11199:19)
    at Object.Container.lookup (http://localhost:8000/vendor/ember/ember.js:10878:16)
    at Ember.Object.extend.adapterFor (http://localhost:8000/vendor/ember-data/ember-data.js:10109:78)
    at Ember.Object.extend.fetchAll (http://localhost:8000/vendor/ember-data/ember-data.js:9417:28)
    at Ember.Object.extend.findAll (http://localhost:8000/vendor/ember-data/ember-data.js:9406:21)
    at Ember.Object.extend.find (http://localhost:8000/vendor/ember-data/ember-data.js:9073:23)
    at Ember.Route.extend.model (http://localhost:8000/assets/app.js:148:27)
    at superWrapper [as model] (http://localhost:8000/vendor/ember/ember.js:1239:16)
    at Ember.Route.Ember.Object.extend.deserialize (http://localhost:8000/vendor/ember/ember.js:35901:19)

The funny thing is if I pass a model that doesn’t exist ( @store.find('some_model') I get an error about the model not existing and not the undefined is not a function error. So I believe its doing a correct lookup on my Question model but something else is going on.