A lot of undefined relationship in calculated relationship Unable to read property 'reject' of indefinite


Given that I have the following


var Artistecontract = ErrorManaged.extend({
  name: DS.attr('string'),
  email: DS.attr('string'),
  signatoryEmail: DS.attr('string'),
  address: DS.attr('string'),
  engagements: DS.hasMany('engagement', { async: true }),
  artisteproject: DS.belongsTo('artisteproject', { async: true }),


var ArtistecontractEngagementsController = Ember.ObjectController.extend({
  availableEngagements: function () {
    var engagements = this.get('engagements');
    return this.get('artisteproject.engagements').reject(function (engagement) {
      return engagements.contains(engagement)
  }.property('artisteproject.engagements', 'engagements')


var ArtistecontractEngagementRoute = AuthenticatedRoute.extend({
  model: function(params) {
    return this.store.find('artistecontract', params.id);
  actions: {
    include: function (artisteproject, engagement) {
      artisteproject.get('engagements').then(function (engagements) {

When I access the availableEngagements attribute I then receive

Cannot read property 'reject' of undefined

What I want to do Is get a array of engagements from the artisteproject that aren't already in the engagements attribute.

What am I doing wrong? Or is there a better way to do this.

You're calling .reject on this.get('artisteproject.engagements'), but the error message is telling you this.get('artisteproject.engagements') is undefined, meaning either

  1. this.get('artisteproject') is undefined, or
  2. this.get('artisteproject.engagements') is undefined.

Based on the code you posted, you never defined an artisteproject property on the controller. In Ember, whatever you return from the model hook of a route gets set as the model property of the associated controller. So, in your controller code, try this instead: