balderdashy / waterline-sequel

A SQL generator for use in Waterline Adapters
MIT License
16 stars 61 forks source link

defaultLimit = 0 don't works with a sorting param #62

Closed elrancid closed 8 years ago

elrancid commented 9 years ago

I want to disable the defaultLimit option, so for now I've set defaultLimit:-1 in bluprints config (according to this issue). If I make a ajax GET request "mymodel" it works, but if I add a sort option and make GET "mymodel?sort=name ASC" the query was composed with "... ORDER BY "mymodel"."name" ASC LIMIT 0 OFFSET 0" and it don't show rows. I've found a solution changing the line 821 in waterline-sequel/sequel/lib/criteriaProcessor.js from

CriteriaProcessor.prototype.limit = function(options) {
  // Some MySQL hackery here.  For details, see:
  // http://stackoverflow.com/questions/255517/mysql-offset-infinite-rows
  if(options === null || options === undefined) {
    this.queryString += ' LIMIT 184467440737095516 ';
  }
  else {
    this.queryString += ' LIMIT ' + options;
  }
};

to

...
  if(options === null || options === undefined || options === 0) {
...

With the defaultLimit = -1 the options value is zero, so adding " || options === 0" is enough to solve the issue.

sailsbot commented 8 years ago

Thanks for posting, @elrancid. I'm a repo bot-- nice to meet you!

It has been 30 days since there have been any updates or new comments on this page. If this issue has been resolved, feel free to disregard the rest of this message. On the other hand, if you are still waiting on a patch, please:

Thanks so much for your help!