Design pattern for Ember.Select usage with Ember Data (hasMany relationship)

I’m working my way through an example to learn Ember.js + Ember Data and I’m struggling on Ember.Select’s usage with Ember Data.

On my first go, google led me to believe I had to handle the relationships manually by using a placeholder on the controller for Ember.Select’s selection property and with pushes for the child object(s) during saves. I also used the foreign controller to store the ‘lookup’ options for the Select’s content property. But this felt wrong as I was hijacking the controller and force-feeding it content. (Vs. using the foreign route to load the model.)

I’m now using a property on the local controlller to create an array for the select’s options, along with another computed property for sorting, and filling it in during the setupController on the local route. (For page refreshes if the foreign model has not been loaded into the store.)

And more importantly, I realized I could use the model’s hasMany relationship property as the selection key in my template. (Which felt much better.) This works beautifully except for the fact that it throws a big old error on my ‘New’ form and works great on my ‘Edit’ form if relationships are already assigned, until a user selects the supplied prompt (null) option. Then it throws an error:

My questions:

  1. Am I doing this somewhat correctly? Or am I off the reservation on usage?
  2. Is it ‘proper Ember’ to use the foreign controller to hold the lookup/option values during this view? (It works, but what happens if I end up displaying both items at the same time down the road.)
  3. What about the selection value? Should I use the local model’s property or a specific new property on the controller?
  4. Does anyone know of a good, simple, straight-forward Ember Data example app out there anywhere? (Preferably without mixins, etc.) There are plenty of post/comment snippets within Ember’s documentation for different functions of an app, but nothing that I’ve found that puts together a fully working multi-relationship CRUD example.
  5. Should I be posting this on stackoverflow? Or is this forum okay with general questions about concepts? (I figured this is kind of a mix.)

Error on menu-items/new route load:

Uncaught Error: Assertion Failed: The content property of DS.PromiseArray should be set before modifying it
Ember Debugger Active 

Error on menu-items/:menu-item_id/edit route when selecting prompt/null value:

"Uncaught TypeError: Cannot read property 'constructor' of undefined"


  • I’ve stripped down the files for the menu-items/new route to the Ember.Selet related stuff. Hopefully I’ve included everything needed to debug.
  • I’m using ember-cli, so I think I have the naming conventions correct (with dashes.)
  • I’ve left debugging in as this helps my understanding of when/what/where things happen.


import Ember from 'ember';

var Router = Ember.Router.extend({
  location: FoodieFoodENV.locationType
}); {
	this.resource('menu-items', function(){
		this.resource('menu-item', { path: '/:menu-item_id' }, function() {
	this.resource('food-groups', function(){
		this.resource('food-group', { path: '/:food-group_id' }, function() {

export default Router;


import DS from 'ember-data';

export default DS.Model.extend({
	title: DS.attr('string'),
	description: DS.attr('string'),
	foodGroups: DS.hasMany('food-group', { 'async': true })


import DS from 'ember-data';

export default DS.Model.extend({
	title: DS.attr('string'),
	description: DS.attr('string'),
	menuItems: DS.hasMany('menu-item')


import Ember from 'ember';

export default Ember.Route.extend({
  model: function(){ + ':model()');
  // afterModel: function(record, transition){
  // + ':afterModel()');
  //   console.log('record', record);
  //   console.groupEnd();
  //   i tried returning a promise here for filling in the controller lookup value, but from what I could tell, it happens before the controller is inited.
  // },
  setupController: function (controller, model) { + ':setupController()');
    console.log('controller', controller);
    console.log('model', model);

    this._super(controller, model);


import Ember from 'ember';

export default Ember.ObjectController.extend({
  foodGroupsAll: Ember.A(),
  foodGroupsSorting: ['title:asc'],
  foodGroupsLookup: Ember.computed.sort('foodGroupsAll', 'foodGroupsSorting'),
  // foodGroupsAllLog: function() {
  // + 'foodGroupsAllLog');
  //   console.log('foodGroupsAll', this.get('foodGroupsAll'));
  //   console.groupEnd();
  // }.property('foodGroupsAll'),
  init: function() {
    this._super(); + ':init()');


<div class="form-group">
    <label for="input-food-groups" class="control-label">Food Group(s)</label>
    {{view Ember.Select content=foodGroupsLookup 
        prompt="Choose Food Group" 


{{log ''}}
{{log 'NEW-FORM'}}
{{log 'form:foodGroupsLookup' foodGroupsLookup}}

Console output:

DEBUG: -------------------------------
DEBUG: Ember      : 1.5.1 
DEBUG: Ember Data : 1.0.0-beta.8.2a68c63a
DEBUG: Handlebars : 1.3.0
DEBUG: jQuery     : 1.11.1
DEBUG: -------------------------------
  Class {id: "1i5em", store: Class, container: Container, _changesToSync: Object, _deferredTriggers: Array[0]…}
    Class {toString: function, __ember1407354815271: "ember416", __nextSuper: undefined, __ember1407354815271_meta: Object, constructor: function…}
    Class {id: "1i5em", store: Class, container: Container, _changesToSync: Object, _deferredTriggers: Array[0]…}
Transitioned into '' vendor.js:16672
[Class, Class, Class, Class, Class, Class, Class, __nextSuper: undefined, __ember1407354815271_meta: Object, __ember1407354815271: "ember540", _super: function, nextObject: function…]

I found out this is a known issue:

this is a known issue, use rel.content for now.

…but I don’t know what "rel.content’ is referring to? I tried all different combinations of content/rel.content/controller scopes on my select’s content attribute, but it’s still not working. Can anyone shed any light on this for me? Please?

Rel == Relationship, in your case it would be foodGroups.content.

In ember data, related records are stored in a ManyArray which proxies the array and does some ED magic. When you declare aysnc: true, the ManyArray is again wrapped in a PromiseProxy. The select view doesn’t seem to play nice with PromiseProxies.


Thank you Joe.

Your answer is exactly what I was hoping for. A clear/working solution and an explanation that makes complete sense. (And allows me to stop obsessing over this issue.)

1 Like