I'm new to Ember CLI and I've been trying to push data to hasMany relationship after it has been created, but I'm getting this weird error Uncaught TypeError: Cannot read property 'push' of undefined Everything seems to be fine this.store.createRecord() is working but .findRecord .push .peekRecord is not working.
My controller:
var VideoToAdd = this.store.find('video', this.get('ActiveCanvas'));
console.log(this.get('ActiveCanvas'));
VideoToAdd.get('hotspots').push(newHotspot);
Video Model
import DS from 'ember-data';
export default DS.Model.extend({
title: DS.attr(),
file: DS.attr(),
hotspots: DS.hasMany('hotspot')
});
Hotspot Model:
import DS from 'ember-data';
export default DS.Model.extend({
title: DS.attr(),
onVideo: DS.belongsTo('video'),
toVideo: DS.attr()
});
Please tell me what's going wrong.
VideoToAdd.get('hotspots').addObject(newHotspot), or.addObjectsif it's an array of hotspots. You could also use.pushObjectand.pushObjects, but using 'add' will check to make sure that the record doesn't already exist in the array, so it's a little bit safer.