Cannot load associated records from a router


#1

Hello,

I have a router that loads a “Place”.

App.PlaceRoute = Ember.Route.extend({
		model: function(params) {
			return this.store.find('place', params.place_id);
		},
		setupController: function(controller, model) {
			this._super(controller, model);
			
			//The promise way ?
			var placeId = model.get('id');
			var myRecords = this.store.find('record', {place:placeId}).then(function(recs){
					console.log("DOES IT HAPPEN ?"); //Never logged
					this.controllerFor('records').set('content', recs);
			});
			
			//Or is the good way below ?
			//this.controllerFor('records').set('content', myRecords);

			//The only that works (which is not I want but displays as I'd like):
			//this.controllerFor('records').set('content', App.Record.FIXTURES);

			this.controllerFor('places').set('content', this.store.find('place'));
		},
		renderTemplate: function(){
			this.render('place', {
					controller: 'place'  
			});
			this.render('display-graph-list', {
					into: 'place',
					outlet: 'graphs',
					controller: 'records'  
			});
		}
	});

This Place has associated “Records”.

App.Place = DS.Model.extend({
		name: attr('string')
		, desc: attr('string')
		, records: hasMany('record')
		, site: belongsTo("site")
	});
	
	App.Record = DS.Model.extend({
			name: attr('string'),
			type: attr('string'),
			data: attr('string'),
			place: belongsTo('place')
	});

As indicated into ember-data 1.0.0 Transition Guide, it uses promises to retrieve data, but here, nothing happens.

Here is a JSbin to see what I mean: http://jsbin.com/iMEdOCe/6/

When I navigate to a place, I should have at least one record displayed.

I cannot figure out how to load and display the records. What do I miss ?

Is there a better way to display an array of sub-items of a model ?


#2

This is a combination of two issues in ember-data 1.0.0-beta.1

The lack of display is due to hasMany/belongsTo relationships: commenting these lines into App.Place and App.Record make something displayed.

See https://github.com/emberjs/data/issues/1177

However another problem appears: the ‘data’ keyword should not be used.

Replacing it with something like ‘datapath’ makes it work.

See https://github.com/emberjs/data/issues/1211