Sails: multiple sort order error

Created on 4 May 2014  路  11Comments  路  Source: balderdashy/sails

when I use sort like .sort('firstletter asc').sort('id asc') the Query sql is ORDER BY b.id asc, b.firstletter asc, but I need ORDER BY b.firstletter asc, b.id asc, please fix it!

Most helpful comment

@ziegler Got it- have you tried the other sort syntax? It'll help narrow this down (I just pushed a fix to sails-disk for a similar issue)

Example of alternate sort syntax:

Foo.find({
  where: {},
  skip: 0,
  limit: 30,
  sort: {
    firstletter: 1,
    id: 1
  }
})
.exec(.....)

(-1 would mean DESC, like mongo syntax)

Basically sort modifiers get transformed into that vector before being passed to the adapter, so testing that out can help us figure out whether this is a sails-MySQL or waterline core issue

Thanks!

All 11 comments

Zieglar - what waterline version and adapter are you using? Is that SQL not working , or is this a style preference? Thanks!

waterline version is 0.10.0-rc12
adapter version is 0.10.0-rc5
this style is not me need, cause I need order firstletter first, then order id second.
Thanks!

@ziegler Got it- have you tried the other sort syntax? It'll help narrow this down (I just pushed a fix to sails-disk for a similar issue)

Example of alternate sort syntax:

Foo.find({
  where: {},
  skip: 0,
  limit: 30,
  sort: {
    firstletter: 1,
    id: 1
  }
})
.exec(.....)

(-1 would mean DESC, like mongo syntax)

Basically sort modifiers get transformed into that vector before being passed to the adapter, so testing that out can help us figure out whether this is a sails-MySQL or waterline core issue

Thanks!

oops, correcting previous comment, sorry

OK, I will try it :)

Sorry open again, this syntax not working
sortnotworking

Just tried with both the latest mysql and postgresql and it worked as expected. Can you throw a console.log(attrName) in https://github.com/balderdashy/sails-mysql/blob/master/lib/sql.js#L307 and see what order it's building the query in?

thanks @particlebanana ,
my sails-mysql version is 0.10 https://github.com/balderdashy/sails-mysql/blob/v0.10/lib/sql.js#L307
result is here
sortfail

sorry ,the same for
Brand.find({ sort: { firstletter: 1, id: 1 })

@zieglar, are you still experiencing this? Which adapter are you using? Thanks

Closing this as duplicate of #694 which has a few suggestions on how to fix this. Thanks!

Was this page helpful?
0 / 5 - 0 ratings