Reputation: 3168
I'm just starting to learn ember and am writing a simple app that reads from a database. I've gotten it to work with fixtures how I want and have just started making some progress reading from a database. Right now my problem is that I can't access children elements - I have a parent class that I am responding to with json through a serializer, and I am serving the children elements in the json request. However, I don't know where to go from here to get the parent class in ember to read and display the children elements. It may make some more sense with the code below.
Let me know if you need any other code - it's all the standard Ember code no specifications! The only lead I'm goin on is my current nested ruby routes are serving as cohorts/:id/boots/:id while ember when using fixture data loads cohorts/:id/:id :)
Models:
Plato.Boot = DS.Model.extend(
name: DS.attr("string"),
cohort: DS.belongsTo('Plato.Cohort'),
hubs: DS.hasMany('Plato.Hub')
)
Plato.Cohort = DS.Model.extend(
name: DS.attr('string'),
boots: DS.hasMany('Plato.Boot')
)
Route.rb
root to: 'application#index'
resources :cohorts do
resources :boots
end
resources :boots
Cohort (parent) controller
class CohortsController < ApplicationController
respond_to :json
def index
respond_with Cohort.all
end
def show
respond_with Cohort.find(params[:id])
end
end
Boot (child) controller
class BootsController < ApplicationController
respond_to :json
def index
respond_with Boot.all
end
def show
respond_with Boot.find(params[:id])
end
end
Router.js.coffee
Plato.Router.map ()->
this.resource('cohorts', ->
this.resource('cohort', {path: '/:cohort_id'}, ->
this.resource('boot', {path: 'boots/:boot_id'})
)
)
Plato.CohortsRoute = Ember.Route.extend(
model: ->
Plato.Cohort.find()
)
Plato.BootsRoute = Ember.Route.extend(
model: ->
Plato.Boot.find(params)
)
Upvotes: 0
Views: 172
Reputation: 23322
Have you tried defining your embedded records boots
in your router map?
For example:
Plato.Adapter = DS.RESTAdapter.extend();
Plato.Store = DS.Store.extend({
adapter: Plato.Adapter
});
Plato.Adapter.map('Plato.Cohort', {
boots: {embedded: 'always'}
});
This way the embedded records will be loaded together with the parent records.
Hope it helps.
Upvotes: 1