Skip to content

Commit

Permalink
Add reverse class method.
Browse files Browse the repository at this point in the history
  • Loading branch information
benpickles committed Sep 10, 2010
1 parent 782c74a commit c728c03
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/model_class_methods.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,10 @@ Model.ClassMethods = {
}
},

reverse: function() {
return this.chain(this.all().reverse())
},

select: function(func) {
var all = this.all(),
selected = [],
Expand Down
10 changes: 10 additions & 0 deletions test/tests/model_class_methods.js
Original file line number Diff line number Diff line change
Expand Up @@ -282,3 +282,13 @@ test("load", function() {

ok(Post.load() === Post, "shouldn't fail if there's no callback (and return self)")
})

test("reverse", function() {
var Post = Model("post")
var post1 = new Post()
var post2 = new Post()

Post.add(post1, post2)

same(Post.reverse().all(), [post2, post1])
})

0 comments on commit c728c03

Please sign in to comment.