Last active
          October 6, 2016 20:27 
        
      - 
      
- 
        Save roooodcastro/7afe4f2877f0ec1681d350def8406902 to your computer and use it in GitHub Desktop. 
    Fixes Arel's pagination issue for Oracle https://github.com/rails/arel/issues/438
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | if o.limit && o.offset | |
| o = o.dup | |
| limit = o.limit.expr | |
| offset = o.offset | |
| o.offset = nil | |
| offset_bind = nil | |
| collector << " | |
| SELECT * FROM ( | |
| SELECT raw_sql_.*, rownum raw_rnum_ | |
| FROM (" | |
| collector = super(o, collector) | |
| collector << ') raw_sql_ WHERE rownum <= (' | |
| collector.add_bind(offset.expr) { |i| offset_bind = ":a#{i}" } | |
| collector << ' + ' | |
| collector.add_bind(limit) { |i| ":a#{i}" } | |
| collector << ") ) WHERE raw_rnum_ > #{offset_bind}" | |
| return collector | |
| end | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment
  
            
Based on rootatdarkstar's solution