Skip to content

Instantly share code, notes, and snippets.

@hashg
Created September 8, 2013 17:28
Show Gist options
  • Save hashg/6486697 to your computer and use it in GitHub Desktop.
Save hashg/6486697 to your computer and use it in GitHub Desktop.
Ember Model. Adding BelongsTo.
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