Created
February 13, 2012 22:04
-
-
Save pixelcort/1820866 to your computer and use it in GitHub Desktop.
relationships using DS.Store#filter
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.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