From f854b46aba0cdd8c6eb92ef038e1e6a3c3aa17f6 Mon Sep 17 00:00:00 2001 From: Ryuta Kamizono Date: Tue, 17 Dec 2019 15:51:05 +0900 Subject: [PATCH] Refactor query methods not to depend on internal `DEFAULT_VALUES` constant This constant is no longer useful since 58df9a452fa75f10365849775292dcf0ae79a6f2. --- .../active_record/relation/query_methods.rb | 19 ++++--------------- 1 file changed, 4 insertions(+), 15 deletions(-) diff --git a/activerecord/lib/active_record/relation/query_methods.rb b/activerecord/lib/active_record/relation/query_methods.rb index a9efa82759..2566f656ea 100644 --- a/activerecord/lib/active_record/relation/query_methods.rb +++ b/activerecord/lib/active_record/relation/query_methods.rb @@ -90,7 +90,7 @@ def not_behaves_as_nor?(opts) when *Relation::SINGLE_VALUE_METHODS ["#{name}_value", name == :create_with ? "FROZEN_EMPTY_HASH" : "nil"] when *Relation::CLAUSE_METHODS - ["#{name}_clause", "DEFAULT_VALUES[:#{name}]"] + ["#{name}_clause", name == :from ? "Relation::FromClause.empty" : "Relation::WhereClause.empty"] end class_eval <<-CODE, __FILE__, __LINE__ + 1 @@ -447,7 +447,7 @@ def unscope!(*args) # :nodoc: raise ArgumentError, "Called unscope() with invalid unscoping argument ':#{scope}'. Valid arguments are :#{VALID_UNSCOPING_VALUES.to_a.join(", :")}." end assert_mutability! - @values[scope] = DEFAULT_VALUES[scope] + @values.delete(scope) when Hash scope.each do |key, target_value| if key != :where @@ -1361,8 +1361,8 @@ def check_if_method_has_arguments!(method_name, args) def structurally_incompatible_values_for_or(other) values = other.values STRUCTURAL_OR_METHODS.reject do |method| - default = DEFAULT_VALUES[method] - @values.fetch(method, default) == values.fetch(method, default) + v1, v2 = @values[method], values[method] + v1 == v2 || (!v1 || v1.empty?) && (!v2 || v2.empty?) end end @@ -1370,16 +1370,5 @@ def where_clause_factory @where_clause_factory ||= Relation::WhereClauseFactory.new(klass, predicate_builder) end alias having_clause_factory where_clause_factory - - DEFAULT_VALUES = { - create_with: FROZEN_EMPTY_HASH, - where: Relation::WhereClause.empty, - having: Relation::WhereClause.empty, - from: Relation::FromClause.empty - } - - Relation::MULTI_VALUE_METHODS.each do |value| - DEFAULT_VALUES[value] ||= FROZEN_EMPTY_ARRAY - end end end -- GitLab