Last active
April 12, 2016 13:38
-
-
Save sajt/06906f3062e7c6108b41fa73688d816c to your computer and use it in GitHub Desktop.
BelongsTo example and question
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//app/models/cake.js | |
import DS from 'ember-data'; | |
import Ember from 'ember'; | |
export default DS.Model.extend({ | |
name: DS.attr('string'), | |
factory: DS.belongsTo('factory', { async: true }), | |
factoryId: Ember.computed('factory', function() { | |
return this.get('factory.id'); | |
}), | |
}), |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
actions: { | |
saveCake(cake) { | |
this.store.findRecord('factory', cake.factoryId).then((factory) => { | |
cake.set('factory', factory); | |
cake.save().then(() => this.transitionTo('admin.cake'), | |
(error) => { | |
Ember.Logger.debug(error); | |
}); | |
}); | |
}, | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment