提交 10f6cb8e 编写于 作者: R Ryuta Kamizono

Refactor `build_where_clause` to avoid extra allocation and code duplication

上级 9bdf6a35
......@@ -673,7 +673,7 @@ def where(opts = :chain, *rest)
end
def where!(opts, *rest) # :nodoc:
self.where_clause += build_where_clause(opts, *rest)
self.where_clause += build_where_clause(opts, rest)
self
end
......@@ -740,9 +740,7 @@ def having(opts, *rest)
end
def having!(opts, *rest) # :nodoc:
opts = sanitize_forbidden_attributes(opts)
self.references_values |= PredicateBuilder.references(opts) if Hash === opts
self.having_clause += having_clause_factory.build(opts, rest)
self.having_clause += build_having_clause(opts, rest)
self
end
......@@ -1076,11 +1074,12 @@ def build_subquery(subquery_alias, select_value) # :nodoc:
end
end
def build_where_clause(opts, *rest)
def build_where_clause(opts, rest = []) # :nodoc:
opts = sanitize_forbidden_attributes(opts)
self.references_values |= PredicateBuilder.references(opts) if Hash === opts
where_clause_factory.build(opts, rest)
end
alias :build_having_clause :build_where_clause
private
def assert_mutability!
......@@ -1461,6 +1460,5 @@ def structurally_incompatible_values_for_or(other)
def where_clause_factory
@where_clause_factory ||= Relation::WhereClauseFactory.new(klass, predicate_builder)
end
alias having_clause_factory where_clause_factory
end
end
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册