Skip to content

Commit

Permalink
Merge pull request #552 from albertogasparin/fix-sort-order
Browse files Browse the repository at this point in the history
Sort order consistent and starting from 0
  • Loading branch information
JedWatson committed Aug 18, 2014
2 parents 581ae34 + 37807ed commit 0b6c501
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/schemaPlugins.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ exports.sortable = function() {

this.schema.pre('save', function(next) {

if (this.sortOrder) {
if (typeof this.sortOrder === 'number') {
return next();
}

var item = this;

list.model.findOne().sort('-sortOrder').exec(function(err, max) {
item.sortOrder = (max && max.sortOrder) ? max.sortOrder + 1 : 1;
item.sortOrder = (max && max.sortOrder) ? max.sortOrder + 1 : 0;
next();
});

Expand Down

0 comments on commit 0b6c501

Please sign in to comment.