Skip to content

Instantly share code, notes, and snippets.

@pixelcort
Created February 13, 2012 22:04
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pixelcort/1820866 to your computer and use it in GitHub Desktop.
Save pixelcort/1820866 to your computer and use it in GitHub Desktop.
relationships using DS.Store#filter
App.FirstModel = DS.Model.extend({
foreignUnsorted: function() {
return App.store.filter(App.ForeignModel, function(hash) {
return false;
});
}.property().cacheable(),
foreign: function() {
var foreignUnsorted = this.get('foreignUnsorted');
return foreignUnsorted.toArray().sort(function(a,b) {
return a.get('sortProperty') - b.get('sortProperty');
});
}.property('foreignUnsorted.@each').cacheable(),
isLoadedDidChange: function() {
var id = this.get('id');
if (!id) return;
if (this._filterFunctionsSet) return;
this.setPath('foreignUnsorted.filterFunction', function(hash) {
return hash.other_id === id;
});
this._filterFunctionsSet = true;
}.observes('isLoaded','id'),
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment