aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAaron Patterson <aaron.patterson@gmail.com>2011-02-25 15:19:11 -0800
committerAaron Patterson <aaron.patterson@gmail.com>2011-02-25 15:19:11 -0800
commitabffef945a64a32ac959ee11d41593d575bcccab (patch)
tree4a23d5ca695a14debe253e0123add70e5714fced
parent6b021764ff16bbab92f8c27ea8f93f1c8df6bd50 (diff)
downloadrails-abffef945a64a32ac959ee11d41593d575bcccab.tar.gz
rails-abffef945a64a32ac959ee11d41593d575bcccab.tar.bz2
rails-abffef945a64a32ac959ee11d41593d575bcccab.zip
Adding SelectManager#limit= and removing limit nodes when nil is assigned to limit
-rw-r--r--History.txt2
-rw-r--r--lib/arel/select_manager.rb10
-rw-r--r--test/test_select_manager.rb9
3 files changed, 19 insertions, 2 deletions
diff --git a/History.txt b/History.txt
index aa5bbd77e2..a931afd0ef 100644
--- a/History.txt
+++ b/History.txt
@@ -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
diff --git a/lib/arel/select_manager.rb b/lib/arel/select_manager.rb
index adffcca764..37405b4596 100644
--- a/lib/arel/select_manager.rb
+++ b/lib/arel/select_manager.rb
@@ -172,10 +172,16 @@ module Arel
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?
diff --git a/test/test_select_manager.rb b/test/test_select_manager.rb
index 4b4733db97..efea44d56f 100644
--- a/test/test_select_manager.rb
+++ b/test/test_select_manager.rb
@@ -743,6 +743,15 @@ module Arel
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