Sha256: a722dc6376207f7bf387a81b533cf3471f641ca324ce41ed3f28a28aa8d8be53

Contents?: true

Size: 1.62 KB

Versions: 15

Compression:

Stored size: 1.62 KB

Contents

module Torque
  module PostgreSQL
    module Relation
      module Merger

        def merge # :nodoc:
          super

          merge_select_extra
          merge_distinct_on
          merge_auxiliary_statements
          merge_inheritance

          relation
        end

        private

          # Merge extra select columns
          def merge_select_extra
            relation.select_extra_values.concat(other.select_extra_values).uniq! \
              if other.select_extra_values.present?
          end

          # Merge distinct on columns
          def merge_distinct_on
            return if other.distinct_on_values.blank?
            relation.distinct_on_values += other.distinct_on_values
          end

          # Merge auxiliary statements activated by +with+
          def merge_auxiliary_statements
            return if other.auxiliary_statements_values.blank?

            current = relation.auxiliary_statements_values.map{ |cte| cte.class }
            other.auxiliary_statements_values.each do |other|
              next if current.include?(other.class)
              relation.auxiliary_statements_values += [other]
              current << other.class
            end
          end

          # Merge settings related to inheritance tables
          def merge_inheritance
            relation.itself_only_value = true if other.itself_only_value.present?

            if other.cast_records_value.present?
              relation.cast_records_value += other.cast_records_value
              relation.cast_records_value.uniq!
            end
          end

      end

      ActiveRecord::Relation::Merger.prepend Merger
    end
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
torque-postgresql-1.1.8 lib/torque/postgresql/relation/merger.rb
torque-postgresql-1.1.7 lib/torque/postgresql/relation/merger.rb
torque-postgresql-2.0.3 lib/torque/postgresql/relation/merger.rb
torque-postgresql-2.0.2 lib/torque/postgresql/relation/merger.rb
torque-postgresql-1.1.6 lib/torque/postgresql/relation/merger.rb
torque-postgresql-1.1.5 lib/torque/postgresql/relation/merger.rb
torque-postgresql-2.0.1 lib/torque/postgresql/relation/merger.rb
torque-postgresql-2.0.0 lib/torque/postgresql/relation/merger.rb
torque-postgresql-1.1.4 lib/torque/postgresql/relation/merger.rb
torque-postgresql-1.1.3 lib/torque/postgresql/relation/merger.rb
torque-postgresql-1.1.2 lib/torque/postgresql/relation/merger.rb
torque-postgresql-1.1.1 lib/torque/postgresql/relation/merger.rb
torque-postgresql-1.1.0 lib/torque/postgresql/relation/merger.rb
torque-postgresql-1.0.1 lib/torque/postgresql/relation/merger.rb
torque-postgresql-1.0.0 lib/torque/postgresql/relation/merger.rb