0

I am trying to display some CI information via an ember application backed by Firebase. If I do a this.store.find('plan'); it fetches and displays the plans for the desired project, but it doesn't automatically async fetch the plans like I want. I am not quite sure what I am doing wrong.

DEBUG: -------------------------------
DEBUG: Ember      : 1.9.0-beta.1+canary.8105a1bb 
DEBUG: Ember Data : 1.0.0-beta.11+canary.d96c747da5
DEBUG: EmberFire  : 1.2.7
DEBUG: Handlebars : 1.3.0
DEBUG: jQuery     : 1.10.2
DEBUG: ------------------------------- 


App = Ember.Application.create();

App.Router.map(function() {
  // put your routes here
});

App.IndexRoute = Ember.Route.extend({
  model: function() {
    return this.store.find('project');
  }
});

App.ApplicationAdapter = DS.FirebaseAdapter.extend({
  firebase: new Firebase('https://my.firebaseio.com/api-data/')
});

App.Project = DS.Model.extend({
  name: DS.attr('string'),
  plans: DS.hasMany('plan', { async: true })
});

App.Plan = DS.Model.extend({
  project: DS.belongsTo('project', { async: true }),
  shortName: DS.attr('string'),
  shortKey: DS.attr('string'),
  type: DS.attr('string'),
  enabled: DS.attr('boolean'),
  name: DS.attr('string'),
  description: DS.attr('string'),
  isBuilding: DS.attr('boolean'),
  averageBuildTimeInSeconds: DS.attr('number')
});

My template

  <script type="text/x-handlebars" data-template-name="index">
    <ul>
    {{#each project in model}}
      <li>
        <h3>{{project.name}}</h3>
        <ul>
          {{#each plan in project.plans}}
            <li>{{plan.name}}</li>
          {{else}}
            <li>no plans</li>
          {{/each}}
         </ul>
      </li>
    {{/each}}
    </ul>
  </script>

How can I get the ember-data async relationship to automatically fetch when I try to access the project.plans property?

Edit:

I have tried mocking with Ember-CLI's http-mock and am sending back the following for /projects

{"plans":[{id: '10', project: '1', name: 'test', plans: ['10']}]}

Which is now working with adding the plans array. I now just need to figure out how this works on firebase.

RyanHirsch
  • 1,847
  • 1
  • 22
  • 37
  • Ember Data does it when you attempt to access it, it appears you're already doing this, so what's the ajax coming back when you query the projects? And have you checked to see if there is a request for plans when you see the page? – Kingpin2k Oct 12 '14 at 20:48
  • Can you post the JSON response for the project endpoint? I suspect it's not setup correctly. – Peter Brown Oct 12 '14 at 21:02
  • I am using Firebase as my backing data store, but have tried mocking with Ember-CLI's http-mock – RyanHirsch Oct 12 '14 at 21:31
  • So the reason should have been obvious on my mock, I don't have my plan's array in that payload, should be something like: `{"plans":[{id: '10', project: '1', name: 'test', plans: ['10']}]}`. So I am guessing I just don't know how to properly populate this on Firebase. – RyanHirsch Oct 12 '14 at 22:06

1 Answers1

0

When using Firebase after my initial seed data, I fetched each model type and called save on all instances. This caused Firebase to be properly populated for the async data array. This was persisted as follows:

/projects

{
    "AS": {
        "name": "AS",
        "plans": {
            "AS-AS": true
        }
    },
    "F": {
        "name": "F",
        "plans": {
            "F-INT": true,
            "F-QA": true,
            "F-STAG": true
        }
    }
}

/plans

{
    "AS-AS": {
        "averageBuildTimeInSeconds": 23,
        "description": "",
        "enabled": true,
        "isBuilding": false,
        "name": "AS - AS",
        "project": "AS",
        "shortKey": "AS",
        "shortName": "AS",
        "type": "chain"
    },
    "F-INT": {
        "averageBuildTimeInSeconds": 18,
        "description": "Integration build",
        "enabled": true,
        "isBuilding": false,
        "name": "F - Integration",
        "project": "F",
        "shortKey": "INT",
        "shortName": "Integration",
        "type": "chain"
    },
    "F-QA": {
        "averageBuildTimeInSeconds": 38,
        "description": "Release from Stage to QA",
        "enabled": true,
        "isBuilding": false,
        "name": "F - QA",
        "project": "F",
        "shortKey": "QA",
        "shortName": "QA",
        "type": "chain"
    },
    "F-STAG": {
        "averageBuildTimeInSeconds": 16,
        "description": "Stage Build and Deploy",
        "enabled": true,
        "isBuilding": false,
        "name": "F - Stage",
        "project": "F",
        "shortKey": "STAG",
        "shortName": "Stage",
        "type": "chain"
    }
}
RyanHirsch
  • 1,847
  • 1
  • 22
  • 37