mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Adding SelectManager#limit= and removing limit nodes when nil is assigned to limit
This commit is contained in:
parent
6b021764ff
commit
abffef945a
3 changed files with 19 additions and 2 deletions
|
@ -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
|
||||
|
||||
|
|
|
@ -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?
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue