提交 d289e15a 编写于 作者: E Emilio Tagua 提交者: Jeremy Kemper

From and lock should be defined to be consistent with other ivars. Limit and...

From and lock should be defined to be consistent with other ivars. Limit and offset are always defined, no need to test that.

[#4253 state:committed]
Signed-off-by: NJeremy Kemper <jeremy@bitsweat.net>
上级 4f5de7f8
...@@ -15,13 +15,10 @@ class Relation ...@@ -15,13 +15,10 @@ class Relation
def initialize(klass, table) def initialize(klass, table)
@klass, @table = klass, table @klass, @table = klass, table
@readonly_value = nil
@create_with_value = nil
@implicit_readonly = nil @implicit_readonly = nil
@limit_value = nil
@offset_value = nil
@loaded = nil @loaded = nil
SINGLE_VALUE_METHODS.each {|v| instance_variable_set(:"@#{v}_value", nil)}
(ASSOCIATION_METHODS + MULTI_VALUE_METHODS).each {|v| instance_variable_set(:"@#{v}_values", [])} (ASSOCIATION_METHODS + MULTI_VALUE_METHODS).each {|v| instance_variable_set(:"@#{v}_values", [])}
end end
...@@ -62,7 +59,7 @@ def to_a ...@@ -62,7 +59,7 @@ def to_a
preload = @preload_values preload = @preload_values
preload += @includes_values unless eager_loading? preload += @includes_values unless eager_loading?
preload.each {|associations| @klass.send(:preload_associations, @records, associations) } preload.each {|associations| @klass.send(:preload_associations, @records, associations) }
# @readonly_value is true only if set explicity. @implicit_readonly is true if there are JOINS and no explicit SELECT. # @readonly_value is true only if set explicity. @implicit_readonly is true if there are JOINS and no explicit SELECT.
readonly = @readonly_value.nil? ? @implicit_readonly : @readonly_value readonly = @readonly_value.nil? ? @implicit_readonly : @readonly_value
......
...@@ -134,13 +134,8 @@ def build_arel ...@@ -134,13 +134,8 @@ def build_arel
arel = h.is_a?(String) ? arel.having(h) : arel.having(*h) arel = h.is_a?(String) ? arel.having(h) : arel.having(*h)
end end
if defined?(@limit_value) && @limit_value.present? arel = arel.take(@limit_value) if @limit_value.present?
arel = arel.take(@limit_value) arel = arel.skip(@offset_value) if @offset_value.present?
end
if defined?(@offset_value) && @offset_value.present?
arel = arel.skip(@offset_value)
end
@group_values.uniq.each do |g| @group_values.uniq.each do |g|
arel = arel.group(g) if g.present? arel = arel.group(g) if g.present?
...@@ -163,19 +158,14 @@ def build_arel ...@@ -163,19 +158,14 @@ def build_arel
arel = arel.project(quoted_table_name + '.*') arel = arel.project(quoted_table_name + '.*')
end end
arel = arel = @from_value.present? ? arel.from(@from_value) : arel.from(quoted_table_name)
if defined?(@from_value) && @from_value.present?
arel.from(@from_value)
else
arel.from(quoted_table_name)
end
case @lock_value case @lock_value
when TrueClass when TrueClass
arel = arel.lock arel = arel.lock
when String when String
arel = arel.lock(@lock_value) arel = arel.lock(@lock_value)
end if defined?(@lock_value) end if @lock_value.present?
arel arel
end end
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册