Last active
December 22, 2015 19:59
-
-
Save commadelimited/6523695 to your computer and use it in GitHub Desktop.
Ember.js: access property of a belongsTo relationship
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
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 |
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
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'), | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Did you ever figure this out? I'm wondering the same thing.