Question

I have an issue regarding load Ember data from an specific model. First of all I must point out that I'm using require.js to load all dependencies. I load all controllers, view, routes and then, I add them to my global Ember app. Moreover, I have a simple model with a few fields as fixtures.

So, the first time something like App.MyModel.find().toArray().length responses me 0. But when the app has started, if I try to run this sentence I get the right value.

I've attempted to figure out any event or method (in controller or route) that executes after all but I didn't get it. I've attempted to set the controller.content at App.ready without successful result

Could anyone help me please?

Was it helpful?

Solution

The solution in my case was a "fixes set":

  1. I had to split the Ember Application Object in order to set first the instance of DS.Store, and the add to it the "Models"
  2. In the second part of this object I added all the controllers, views, router, etc
  3. Finally, when I extended the DS.Store object I had to set the attribute simulateRemoteResponse: true

The final app.js code was the following:

define(
    [ #dependencies ],

    function( #dependencies_objects ) {

        window.App = Ember.Application.create({
            VERSION: '1.0.0',
            LOG_TRANSITIONS: true,

            rootElement: '#app',

            // Store
            store: DS.Store.create({
                revision: 12,
                adapter : DS.FixtureAdapter.extend({
                    simulateRemoteResponse: false
                })
            }),

            // Models
            Item: Item  // Where Item is my own model
        });

        App.reopen({
            // Routes
            IndexRoute: IndexRoute,

            // Load routes
            Router: Router,

            // Controllers
            ApplicationController: Ember.Controller.extend(),
            IndexController: IndexController
        });

    }
);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top