From 20ea9f6fd3c0a17a6ddf20776e5e2e5f4decdffc Mon Sep 17 00:00:00 2001 From: Emilio Tagua Date: Mon, 22 Mar 2010 15:43:14 -0300 Subject: [PATCH] From and lock should be defined to be consistent with other ivars. Limit and offset are always defined, no need to test that. --- activerecord/lib/active_record/relation.rb | 7 ++----- .../lib/active_record/relation/query_methods.rb | 18 ++++-------------- 2 files changed, 6 insertions(+), 19 deletions(-) diff --git a/activerecord/lib/active_record/relation.rb b/activerecord/lib/active_record/relation.rb index 1a84f70..a20c152 100644 --- a/activerecord/lib/active_record/relation.rb +++ b/activerecord/lib/active_record/relation.rb @@ -15,13 +15,10 @@ module ActiveRecord def initialize(klass, table) @klass, @table = klass, table - @readonly_value = nil - @create_with_value = nil @implicit_readonly = nil - @limit_value = nil - @offset_value = 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", [])} end @@ -62,7 +59,7 @@ module ActiveRecord preload = @preload_values 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 = @readonly_value.nil? ? @implicit_readonly : @readonly_value diff --git a/activerecord/lib/active_record/relation/query_methods.rb b/activerecord/lib/active_record/relation/query_methods.rb index f7cf686..0250e73 100644 --- a/activerecord/lib/active_record/relation/query_methods.rb +++ b/activerecord/lib/active_record/relation/query_methods.rb @@ -134,13 +134,8 @@ module ActiveRecord arel = h.is_a?(String) ? arel.having(h) : arel.having(*h) end - if defined?(@limit_value) && @limit_value.present? - arel = arel.take(@limit_value) - end - - if defined?(@offset_value) && @offset_value.present? - arel = arel.skip(@offset_value) - end + arel = arel.take(@limit_value) if @limit_value.present? + arel = arel.skip(@offset_value) if @offset_value.present? @group_values.uniq.each do |g| arel = arel.group(g) if g.present? @@ -163,19 +158,14 @@ module ActiveRecord arel = arel.project(quoted_table_name + '.*') end - arel = - if defined?(@from_value) && @from_value.present? - arel.from(@from_value) - else - arel.from(quoted_table_name) - end + arel = @from_value.present? ? arel.from(@from_value) : arel.from(quoted_table_name) case @lock_value when TrueClass arel = arel.lock when String arel = arel.lock(@lock_value) - end if defined?(@lock_value) + end if @lock_value.present? arel end -- 1.6.5