Sha256: 16fec0946355a12c0e4d98e073ef419f9beb3476853573436c9001f5c1cb4232

Contents?: true

Size: 1.99 KB

Versions: 17

Compression:

Stored size: 1.99 KB

Contents

module ActiveScaffold
  module OuterJoins
    extend ActiveSupport::Concern
    attr_accessor :outer_joins_values

    if Rails::VERSION::MAJOR < 4
      included do
        const_get(:MULTI_VALUE_METHODS) << :outer_joins
      end

      def outer_joins(*args)
        return self if args.compact.blank?

        relation = clone

        args.flatten!
        relation.joins_values += [''] # HACK for using outer_joins in update_all/delete_all
        relation.outer_joins_values += args

        relation
      end
    else
      def outer_joins_values
        @values[:outer_joins] || []
      end

      def outer_joins_values=(values)
        raise ImmutableRelation if @loaded
        @values[:outer_joins] = values
      end

      def outer_joins(*args)
        check_if_method_has_arguments!("outer_joins", args)
        spawn.outer_joins!(*args.compact.flatten)
      end

      def outer_joins!(*args)
        self.joins_values += [''] # HACK for using outer_joins in update_all/delete_all
        self.outer_joins_values += args
        self
      end
    end

    if Rails.version < '4.1'
      def build_arel
        unless outer_joins_values.empty?
          relation = self.except(:outer_joins)
          join_dependency = ActiveRecord::Associations::JoinDependency.new(@klass, outer_joins_values, [])
          join_dependency.join_associations.each do |association|
            relation = association.join_relation(relation)
          end
          relation.build_arel
        else
          super
        end
      end
    else
      def build_arel
        unless outer_joins_values.empty?
          relation = self.except(:outer_joins)
          relation.joins! ActiveRecord::Associations::JoinDependency.new(@klass, outer_joins_values, [])
          relation.build_arel
        else
          super
        end
      end
    end
  end
end
ActiveRecord::Relation.send :include, ActiveScaffold::OuterJoins
module ActiveRecord::Querying
  delegate :outer_joins, :to => Rails::VERSION::MAJOR < 4 ? :scoped : :all
end

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
active_scaffold-3.4.17 lib/active_scaffold/extensions/left_outer_joins.rb
active_scaffold-3.4.16 lib/active_scaffold/extensions/left_outer_joins.rb
active_scaffold-3.4.14 lib/active_scaffold/extensions/left_outer_joins.rb
active_scaffold-3.4.13 lib/active_scaffold/extensions/left_outer_joins.rb
active_scaffold-3.4.12 lib/active_scaffold/extensions/left_outer_joins.rb
active_scaffold-3.4.11 lib/active_scaffold/extensions/left_outer_joins.rb
active_scaffold-3.4.10 lib/active_scaffold/extensions/left_outer_joins.rb
active_scaffold-3.4.9 lib/active_scaffold/extensions/left_outer_joins.rb
active_scaffold-3.4.8 lib/active_scaffold/extensions/left_outer_joins.rb
active_scaffold-3.4.7 lib/active_scaffold/extensions/left_outer_joins.rb
active_scaffold-3.4.5 lib/active_scaffold/extensions/left_outer_joins.rb
active_scaffold-3.4.4 lib/active_scaffold/extensions/left_outer_joins.rb
active_scaffold-3.4.3 lib/active_scaffold/extensions/left_outer_joins.rb
active_scaffold-3.4.2 lib/active_scaffold/extensions/left_outer_joins.rb
active_scaffold-3.4.1 lib/active_scaffold/extensions/left_outer_joins.rb
active_scaffold-3.4.0.1 lib/active_scaffold/extensions/left_outer_joins.rb
active_scaffold-3.4.0 lib/active_scaffold/extensions/left_outer_joins.rb