Permalink
Browse files

Adding SelectManager#limit= and removing limit nodes when nil is assi…

…gned to limit
  • Loading branch information...
1 parent 6b02176 commit abffef945a64a32ac959ee11d41593d575bcccab @tenderlove tenderlove committed Feb 25, 2011
Showing with 19 additions and 2 deletions.
  1. +2 −0 History.txt
  2. +8 −2 lib/arel/select_manager.rb
  3. +9 −0 test/test_select_manager.rb
View
@@ -6,10 +6,12 @@
* AND nodes are now n-ary nodes
* SQL Literals may be used as Attribute names
* Added Arel::Nodes::NamedFunction for representing generic SQL functions
+ * Add Arel::SelectManager#limit=
* Bug fixes
* MSSQL adds TOP to sub selects
+ * Assigning nil to take() removes LIMIT from statement.
* Deprecations
View
@@ -172,10 +172,16 @@ def with *subqueries
end
def take limit
- @ast.limit = Nodes::Limit.new(limit)
- @ctx.top = Nodes::Top.new(limit)
+ if limit
+ @ast.limit = Nodes::Limit.new(limit)
+ @ctx.top = Nodes::Top.new(limit)
+ else
+ @ast.limit = nil
+ @ctx.top = nil
+ end
self
end
+ alias limit= take
def join_sql
return nil if @ctx.source.right.empty?
@@ -743,6 +743,15 @@ def test_join_sources
manager = Arel::SelectManager.new Table.engine
manager.take(1).must_equal manager
end
+
+ it 'removes LIMIT when nil is passed' do
+ manager = Arel::SelectManager.new Table.engine
+ manager.limit = 10
+ assert_match('LIMIT', manager.to_sql)
+
+ manager.limit = nil
+ refute_match('LIMIT', manager.to_sql)
+ end
end
describe 'where' do

0 comments on commit abffef9

Please sign in to comment.