Skip to content

Instantly share code, notes, and snippets.

@commadelimited
Last active December 22, 2015 19:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save commadelimited/6523695 to your computer and use it in GitHub Desktop.
Save commadelimited/6523695 to your computer and use it in GitHub Desktop.
Ember.js: access property of a belongsTo relationship
I have two models with a one to many relationship. An Account can have many Interactions.
I want to create a computed property on the Interaction which observes a property on the
"parent" model, Account. When I load the page, the provider method triggers, so it seems
as if it's "working" but when I do a log statement in the function I get nothing.
Should I expect to be able to access the other model in this relationship like I'm doing?
Is there a better way? Is this a bug?
Dependencies:
DEBUG: Ember.VERSION : 1.0.0-rc.4
DEBUG: Ember Data VERSION : r13
DEBUG: Handlebars.VERSION : 1.0.0-rc.4
DEBUG: jQuery.VERSION : 1.9.1
Social.Account = DS.Model.extend({
username: DS.attr("string"),
provider: DS.attr("string"),
interactions: DS.hasMany("Social.Interaction"),
});
Social.Interaction = DS.Model.extend({
text: DS.attr('string'),
account: DS.belongsTo("Social.Account"),
provider: function(){
console.log( this.get('account') );
}.observes('account.provider'),
});
@anthonylebrun
Copy link

Did you ever figure this out? I'm wondering the same thing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment