lib/torque/postgresql/relation.rb in torque-postgresql-2.4.5 vs lib/torque/postgresql/relation.rb in torque-postgresql-3.0.0
- old
+ new
@@ -17,10 +17,12 @@
SINGLE_VALUE_METHODS = [:itself_only]
MULTI_VALUE_METHODS = [:distinct_on, :auxiliary_statements, :cast_records, :select_extra]
VALUE_METHODS = SINGLE_VALUE_METHODS + MULTI_VALUE_METHODS
+ ARColumn = ::ActiveRecord::ConnectionAdapters::PostgreSQL::Column
+
# :nodoc:
def select_extra_values; get_value(:select_extra); end
# :nodoc:
def select_extra_values=(value); set_value(:select_extra, value); end
@@ -72,10 +74,18 @@
else
raise ArgumentError, "Relation for #{relation} not found on #{klass}"
end
end
+ # Serialize the given value so it can be used in a condition tha involves
+ # the given column
+ def cast_for_condition(column, value)
+ column = columns_hash[column.to_s] unless column.is_a?(ARColumn)
+ caster = connection.lookup_cast_type_from_column(column)
+ connection.type_cast(caster.serialize(value))
+ end
+
private
def build_arel(*)
arel = super
arel.project(*select_extra_values) if select_values.blank?
@@ -137,21 +147,9 @@
ActiveRecord::Relation::SINGLE_VALUE_METHODS += Relation::SINGLE_VALUE_METHODS
ActiveRecord::Relation::MULTI_VALUE_METHODS += Relation::MULTI_VALUE_METHODS
ActiveRecord::Relation::VALUE_METHODS += Relation::VALUE_METHODS
ActiveRecord::QueryMethods::VALID_UNSCOPING_VALUES += %i[cast_records itself_only
distinct_on auxiliary_statements]
-
- unless AR610
- Relation::SINGLE_VALUE_METHODS.each do |value|
- ActiveRecord::QueryMethods::DEFAULT_VALUES[value] = nil \
- if ActiveRecord::QueryMethods::DEFAULT_VALUES[value].nil?
- end
-
- Relation::MULTI_VALUE_METHODS.each do |value|
- ActiveRecord::QueryMethods::DEFAULT_VALUES[value] ||= \
- ActiveRecord::QueryMethods::FROZEN_EMPTY_ARRAY
- end
- end
$VERBOSE = warn_level
end
end