Closed afeld closed 11 years ago
I've done this before too, but I'd like to avoid it if we can. Do you have a scenario in mind where we would need this?
I was going to try to convert the owner
objects under each app.Issue
to proper app.User
s, where many issues could share the same owner. Maybe doing that nested model isn't necessary, but we might want to point out having duplicate models is something to watch out for.
Well right now we can do
var issuesForLogin = app.board.issues.filter(function (issue) {
return issue.get('user').login === 'afeld';
});
to get issues by submitter. If you want issues by owner
var issuesForOwner = app.board.issues.filter(function (issue) {
return issue.repo.get('owner').login === 'afeld';
});
I think these help showcase the underscore collection methods also.
I like the underscore filter approach.
We use this technique in our framework at @jux: create a special Collection that contains all instantiated Models, so that if you try to create a new Model with the same
'id'
as an existing one, it just gives back that same instance. Has saved a lot of headaches, but I know this isn't necessarily a common Backbone pattern.