Created
September 8, 2013 17:28
-
-
Save hashg/6486697 to your computer and use it in GitHub Desktop.
Ember Model. Adding BelongsTo.
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.Person = Ember.Model.extend({ | |
id: Ember.attr(), | |
name: Ember.attr(), | |
addresses: Ember.hasMany(App.Address, {key: 'addresses'}) | |
}); | |
App.Address = Ember.Model.extend({ | |
id: Ember.attr(), | |
street: Ember.attr(), | |
person_id: Ember.attr(), | |
person: Ember.belongsTo(App.Person, {key: 'person_id'}) | |
}); | |
var myPerson = App.Person.create({id:1, name: 'Erik'}); | |
myPerson.save(); | |
var myAddress = myPerson.get('addresses'); | |
myAddress.create({id:2, street: '6th Street', person_id: myPerson.get('id'), person: myPerson}); | |
myAddress.save() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment