"Has Many" can't create new record


#1

The application is simple, we have many swimming lessons and instructors who administer the lessons. Each lesson can only have one instructor and instructors can have many classes that they teach.

I am new to ember ( and programming in general). Currently, I can see both sides of the relationship; the instructor can see the classes that they teach and the lesson can see who the instructor is. The problem is that I can no longer add any new instructors. I get the following error,

Cannot read property ‘determineRelationshipType’ of undefined

I can add new lessons and indicate who the instructor just fine.

From what I can gather it is an issue with FireBase and Ember data. I have tried downgrading Ember-data to earlier versions as suggested, but with no success.

Within this application I will need to add more of these relationships. For example, each class will have many swimmers. I don’t want to proceed until I know that I can solve this problem.

I am a beginner, please keep this in mind with any suggestions. Thanks!

Relevant code.

App.ApplicationAdapter = DS.FirebaseAdapter.extend({
    firebase: new Firebase("https://splashers-final.firebaseio.com")
  });


App.Router.map(function() {
    this.resource('lessons', { path: '/lessons' }, function() {
      this.resource('lesson', { path: '/:lesson_id' })
      this.route('new', { path: '/new' })
    });

    this.resource('instructors', { path: '/instructors' }, function() {
      this.resource('instructor', { path: '/:instructor_id' })
      this.route('new', { path: '/new' })
    });

  });




App.LessonRoute = Ember.Route.extend({
      model: function(params) {
        return this.store.find('lesson', params.lesson_id);
  }
});

App.LessonController = Ember.ObjectController.extend({
  actions: {
  


    deleteLesson: function () {

      if(confirm("Are you sure you want to delete this lesson?")) 
        {var lesson = this.get('model');
          this.transitionToRoute('lessons'); 
          lesson.deleteRecord();
          lesson.save();
        } 
        else {return}
    },

isExpanded: true,
  
    expand: function() {
      this.set('isExpanded', true);
    },

    contract: function() {
      this.set('isExpanded', false);
    }
  }
  
});

App.LessonsRoute = Ember.Route.extend({
  model: function() {
    return this.store.findAll('lesson')
  }
});

App.LessonsController = Ember.ArrayController.extend({
  lessonCount: Ember.computed.alias('length'),
  groupCount: Ember.computed.alias('length'),
  sortProperties:['classIsFull'],
  sortAscending:true,

});


App.Lesson = DS.Model.extend({
  type: DS.attr(),
  name: DS.attr(),
  /*level: DS.attr(),   sometimes there are hybrid levels, likely leave it up to */
  instructor:DS.belongsTo('instructor', {async: true}),
  startDate: DS.attr(),
  endDate: DS.attr(),
  capacity: DS.attr('number'),
 /* swimmers: DS.hasMany('swimmer', {async: true}),*/
  /*dayAndTime:DS.attr(),*/


      isPrivate: function() {
      return this.get('type') === ('Private');
    }.property('type'),

      isGroup: function() {
      return this.get('type') === ('Group');
    }.property('type'),

      isCamp: function() {
      return this.get('type') === ('Camp');
    }.property('type'),
/*      
      classIsFull: function() {
      return this.get('swimmersInLesson') === this.get('capacity');
    }.property('swimmersInLesson','capacity'),

      classIsEmpty: function() {
      return this.get('swimmersInLesson') ===0;
    }.property('swimmersInLesson'),



      swimmersInLesson: function() {
   return this.get('swimmers.length');
 }.property('swimmers.length'),

*/


  
  });

App.LessonsNewRoute = Ember.Route.extend({
  model: function() {
    return Ember.RSVP.hash({
      lesson: this.store.createRecord('lesson'),
      instructor: this.store.findAll('instructor') 
    });
  },
  setupController: function(controller, model) {
    controller.set('model', model.lesson);
    controller.set('instructor', model.instructor);
  },
  actions: {

    willTransition: function(transition) {
      if(this.currentModel.lesson.get('isNew')) {
        if(confirm("Are you sure you want to abandon progress?")) {
          this.currentModel.lesson.destroyRecord();
          
        } else {
          transition.abort();
        }
      }
    }
  }
});
App.LessonsNewController = Ember.Controller.extend({
 
  lessonTypes:['','Group','Camp','Private', 'Semi-Private'],
  capacity: [1,2,3,4,5,6,7,8],
  actions: {

    createLesson: function() {
      var controller = this;
      this.get('model').save().then(function() {

        controller.transitionToRoute('lessons');
      });
    }
  }
});


App.Instructor = DS.Model.extend({
  nameFirst: DS.attr(),
  nameLast: DS.attr(),
  gender: DS.attr(),
  /*note:DS.attr(),*/
  lessons: DS.hasMany('lesson', {async: true}),

  fullName: function() {
      return this.get('nameFirst') + " " + this.get('nameLast');
    }.property('nameFirst','nameLast'),

  isActive: function() {
      return this.get('numberOfLessons') > 0;
    }.property('numberOfLessons'),

  numberOfLessons: function() {
   return this.get('lessons.length');
 }.property('lessons.length'),
});



App.InstructorsNewRoute = Ember.Route.extend({
  model: function() {
    return Ember.RSVP.hash({
      instructor: this.store.createRecord('instructor'),


      
    });
  },
  setupController: function(controller, model) {
    controller.set('model', model.instructor);
  },
  actions: {

    willTransition: function(transition) {
      if(this.currentModel.instructor.get('isNew')) {
        if(confirm("Are you sure you want to abandon progress?")) {
          this.currentModel.instructor.destroyRecord();
          
        } else {
          transition.abort();
        }
      }
    }
  }
});



App.InstructorRoute = Ember.Route.extend({
   
   /*model: function(params) {
    return this.store.find('instructor', params.instructor_id) */
  
   model: function() {
    return Ember.RSVP.hash({
      instructor: this.store.find('instructor', params.instructor_id),
      lessons: this.store.findAll('lesson')
    });
  },
  actions: {

    willTransition: function(transition) {
      if(this.currentModel.instructor.get('isNew')) {
        if(confirm("Are you sure you want to abandon progress?")) {
          this.currentModel.instructor.destroyRecord();
          
        } else {
          transition.abort();
        }
      }
    }
  }
});



App.InstructorsRoute = Ember.Route.extend({
  needs: 'lessons',
  model: function() {
    return this.store.findAll('instructor')
  }
});

App.InstructorsNewRoute = Ember.Route.extend({
  model: function() {
    return Ember.RSVP.hash({
      instructor: this.store.createRecord('instructor'),
     /* lesson: this.store.findAll('lesson') */
    });
  },
  setupController: function(controller, model) {
    controller.set('model', model.instructor);
    /*controller.set('lesson', model.lesson);*/
  },
  actions: {

    willTransition: function(transition) {
      if(this.currentModel.lesson.get('isNew')) {
        if(confirm("Are you sure you want to abandon progress?")) {
          this.currentModel.lesson.destroyRecord();
          
        } else {
          transition.abort();
        }
      }
    }
  }
});

App.InstructorController = Ember.ObjectController.extend({


  actions: {

    deleteInstructor: function () {

      if(confirm("Are you sure you want to delete this Instructor?")) 
        {var instructor = this.get('model');
          this.transitionToRoute('instructors'); 
          instructor.deleteRecord();
          instructor.save();
        } 
        else {return}
    }
  }
});

App.InstructorsNewController=Ember.ObjectController.extend({
        gender:['','Male','Female'],

  actions:{
        createInstructor: function() {
      var controller = this;
      this.get('model').save().then(function() {
        controller.transitionToRoute('instructors');
      });
  }
}


});

#2

The problem seems to have resolved itself by updating Firebase, to EmberFire : 1.2.6.