lib/torque/postgresql/relation.rb in torque-postgresql-2.0.3 vs lib/torque/postgresql/relation.rb in torque-postgresql-2.0.4
- old
+ new
@@ -1,5 +1,7 @@
+# frozen_string_literal: true
+
require_relative 'relation/distinct_on'
require_relative 'relation/auxiliary_statement'
require_relative 'relation/inheritance'
require_relative 'relation/merger'
@@ -46,16 +48,16 @@
Array.wrap(list).map do |item|
case item
when String
::Arel.sql(klass.send(:sanitize_sql, item.to_s))
when Symbol
- base ? base.arel_attribute(item) : klass.arel_attribute(item)
+ base ? base.arel_table[item] : klass.arel_table[item]
when Array
resolve_column(item, base)
when Hash
raise ArgumentError, 'Unsupported Hash for attributes on third level' if base
- item.map { |key, other_list| resolve_column(Array.wrap(other_list), key) }
+ item.map { |key, other_list| resolve_column(other_list, key) }
else
raise ArgumentError, "Unsupported argument type: #{value} (#{value.class})"
end
end.flatten
end
@@ -63,12 +65,12 @@
# Get the TableMetadata from a relation
def resolve_base_table(relation)
return unless relation
table = predicate_builder.send(:table)
- if table.associated_with?(relation)
- table.associated_table(relation).send(:klass)
+ if table.associated_with?(relation.to_s)
+ table.associated_table(relation.to_s).send(:klass)
else
raise ArgumentError, "Relation for #{relation} not found on #{klass}"
end
end
@@ -136,17 +138,19 @@
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]
- Relation::SINGLE_VALUE_METHODS.each do |value|
- ActiveRecord::QueryMethods::DEFAULT_VALUES[value] = nil \
- if ActiveRecord::QueryMethods::DEFAULT_VALUES[value].nil?
- end
+ 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
+ Relation::MULTI_VALUE_METHODS.each do |value|
+ ActiveRecord::QueryMethods::DEFAULT_VALUES[value] ||= \
+ ActiveRecord::QueryMethods::FROZEN_EMPTY_ARRAY
+ end
end
$VERBOSE = warn_level
end
end