lib/torque/postgresql/relation.rb in torque-postgresql-0.2.16 vs lib/torque/postgresql/relation.rb in torque-postgresql-1.0.0

- old
+ new

@@ -12,13 +12,18 @@ include DistinctOn include AuxiliaryStatement include Inheritance SINGLE_VALUE_METHODS = [:itself_only] - MULTI_VALUE_METHODS = [:distinct_on, :auxiliary_statements, :cast_records] + MULTI_VALUE_METHODS = [:distinct_on, :auxiliary_statements, :cast_records, :select_extra] VALUE_METHODS = SINGLE_VALUE_METHODS + MULTI_VALUE_METHODS + # :nodoc: + def select_extra_values; get_value(:select_extra); end + # :nodoc: + def select_extra_values=(value); set_value(:select_extra, value); end + # Resolve column name when calculating models, allowing the column name to # be more complex while keeping the query selection quality def calculate(operation, column_name) column_name = resolve_column(column_name).first if column_name.is_a?(Hash) super(operation, column_name) @@ -39,11 +44,11 @@ base = resolve_base_table(base) Array.wrap(list).map do |item| case item when String - ::Arel::Nodes::SqlLiteral.new(klass.send(:sanitize_sql, item.to_s)) + ::Arel.sql(klass.send(:sanitize_sql, item.to_s)) when Symbol base ? base.arel_attribute(item) : klass.arel_attribute(item) when Array resolve_column(item, base) when Hash @@ -70,17 +75,13 @@ end end private - def dynamic_selection - @dynamic_selection ||= [] - end - def build_arel(*) arel = super - arel.project(*dynamic_selection) if select_values.blank? && dynamic_selection.any? + arel.project(*select_extra_values) if select_values.blank? arel end # Compatibility method with 5.0 unless ActiveRecord::Relation.method_defined?(:get_value) @@ -132,12 +133,12 @@ ActiveRecord::Relation.prepend Relation::Initializer warn_level = $VERBOSE $VERBOSE = nil - 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::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 += [:cast_records, :itself_only, :distinct_on, :auxiliary_statements] if ActiveRecord::QueryMethods.const_defined?('DEFAULT_VALUES') Relation::SINGLE_VALUE_METHODS.each do |value|