提交 0d65969e 编写于 作者: C Carlos Antonio da Silva

Improve relation docs about to_sql and where_values_hash

* User class instead of Users.
* #where_values_hash does not change the value to downcase as the
  example was showing.

[ci skip]
上级 f209b176
...@@ -474,16 +474,16 @@ def reset ...@@ -474,16 +474,16 @@ def reset
# Returns sql statement for the relation. # Returns sql statement for the relation.
# #
# Users.where(name: 'Oscar').to_sql # User.where(name: 'Oscar').to_sql
# # => SELECT "users".* FROM "users" WHERE "users"."name" = 'Oscar' # # => SELECT "users".* FROM "users" WHERE "users"."name" = 'Oscar'
def to_sql def to_sql
@to_sql ||= klass.connection.to_sql(arel, bind_values.dup) @to_sql ||= klass.connection.to_sql(arel, bind_values.dup)
end end
# Returns a hash of where conditions # Returns a hash of where conditions.
# #
# Users.where(name: 'Oscar').where_values_hash # User.where(name: 'Oscar').where_values_hash
# # => {name: "oscar"} # # => {name: "Oscar"}
def where_values_hash def where_values_hash
equalities = with_default_scope.where_values.grep(Arel::Nodes::Equality).find_all { |node| equalities = with_default_scope.where_values.grep(Arel::Nodes::Equality).find_all { |node|
node.left.relation.name == table_name node.left.relation.name == table_name
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册