vendredi 31 juillet 2015

Ember Data - Unable to add one way belongsTo relation

I have created 2 models a video model and a subtitle model:

Video Model

import DS from 'ember-data';

export default DS.Model.extend({
  title: DS.attr(),
  file: DS.attr(),
  hotspots: DS.hasMany('hotspot', {
    inverse: 'toVideo'
  })
});

Hotspot Model

import DS from 'ember-data';

export default DS.Model.extend({
  title: DS.attr(),
  onVideo: DS.belongsTo('video'),
  toVideo: DS.belongsTo('video')
});

So basically a hotspot is present on a video and links to another video. So I'm able to link the onVideo using the following code:

this.store.find('video', this.get('ActiveCanvas')).then(function(onVideo) {
    onVideo.get('hotspots').pushObject(newHotspot);
});

But now I want to add the toVideo relation but it's not working for some reason. This is what I tried.

var newHotspot = this.store.createRecord('hotspot', {
    title: this.get('HotspotName'),
    toVideo: this.store.find('video', HotspotVideo.value)
});

I'm not getting any error in my console. Can you please tell me what's going wrong.




Aucun commentaire:

Enregistrer un commentaire