mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Extract Arel.arel_node?
helper method
This commit is contained in:
parent
ae406cd633
commit
d0d1cd3d45
3 changed files with 7 additions and 4 deletions
|
@ -194,9 +194,7 @@ module ActiveRecord
|
||||||
|
|
||||||
def disallow_raw_sql!(args, permit: COLUMN_NAME) # :nodoc:
|
def disallow_raw_sql!(args, permit: COLUMN_NAME) # :nodoc:
|
||||||
unexpected = args.reject do |arg|
|
unexpected = args.reject do |arg|
|
||||||
arg.kind_of?(Arel::Node) ||
|
Arel.arel_node?(arg) ||
|
||||||
arg.is_a?(Arel::Nodes::SqlLiteral) ||
|
|
||||||
arg.is_a?(Arel::Attributes::Attribute) ||
|
|
||||||
arg.to_s.split(/\s*,\s*/).all? { |part| permit.match?(part) }
|
arg.to_s.split(/\s*,\s*/).all? { |part| permit.match?(part) }
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -635,7 +635,7 @@ module ActiveRecord
|
||||||
def _substitute_values(values)
|
def _substitute_values(values)
|
||||||
values.map do |name, value|
|
values.map do |name, value|
|
||||||
attr = arel_attribute(name)
|
attr = arel_attribute(name)
|
||||||
unless value.is_a?(Arel::Node) || value.is_a?(Arel::Attribute) || value.is_a?(Arel::Nodes::SqlLiteral)
|
unless Arel.arel_node?(value)
|
||||||
type = klass.type_for_attribute(attr.name)
|
type = klass.type_for_attribute(attr.name)
|
||||||
value = predicate_builder.build_bind_attribute(attr.name, type.cast(value))
|
value = predicate_builder.build_bind_attribute(attr.name, type.cast(value))
|
||||||
end
|
end
|
||||||
|
|
|
@ -35,6 +35,11 @@ module Arel # :nodoc: all
|
||||||
def self.star
|
def self.star
|
||||||
sql "*"
|
sql "*"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def self.arel_node?(value)
|
||||||
|
value.is_a?(Arel::Node) || value.is_a?(Arel::Attribute) || value.is_a?(Arel::Nodes::SqlLiteral)
|
||||||
|
end
|
||||||
|
|
||||||
## Convenience Alias
|
## Convenience Alias
|
||||||
Node = Arel::Nodes::Node
|
Node = Arel::Nodes::Node
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue