Sha256: 72b1dfc8ee073bfe5b47aa644a4e0b5ce0f96077e9f2598a18ff2440d419c2f1

Contents?: true

Size: 1.97 KB

Versions: 29

Compression:

Stored size: 1.97 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
        if outer_joins_values.empty?
          super
        else
          relation = 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
        end
      end
    else
      def build_arel
        if outer_joins_values.empty?
          super
        else
          relation = except(:outer_joins)
          relation.joins! ActiveRecord::Associations::JoinDependency.new(@klass, outer_joins_values, [])
          relation.build_arel
        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

29 entries across 29 versions & 1 rubygems

Version Path
active_scaffold-3.4.43 lib/active_scaffold/extensions/left_outer_joins.rb
active_scaffold-3.4.42 lib/active_scaffold/extensions/left_outer_joins.rb
active_scaffold-3.4.41.1 lib/active_scaffold/extensions/left_outer_joins.rb
active_scaffold-3.4.41 lib/active_scaffold/extensions/left_outer_joins.rb
active_scaffold-3.4.40 lib/active_scaffold/extensions/left_outer_joins.rb
active_scaffold-3.4.39 lib/active_scaffold/extensions/left_outer_joins.rb
active_scaffold-3.4.38 lib/active_scaffold/extensions/left_outer_joins.rb
active_scaffold-3.4.37 lib/active_scaffold/extensions/left_outer_joins.rb
active_scaffold-3.4.36 lib/active_scaffold/extensions/left_outer_joins.rb
active_scaffold-3.4.35 lib/active_scaffold/extensions/left_outer_joins.rb
active_scaffold-3.4.34 lib/active_scaffold/extensions/left_outer_joins.rb
active_scaffold-3.4.33 lib/active_scaffold/extensions/left_outer_joins.rb
active_scaffold-3.4.32 lib/active_scaffold/extensions/left_outer_joins.rb
active_scaffold-3.4.31 lib/active_scaffold/extensions/left_outer_joins.rb
active_scaffold-3.4.30 lib/active_scaffold/extensions/left_outer_joins.rb
active_scaffold-3.4.29 lib/active_scaffold/extensions/left_outer_joins.rb
active_scaffold-3.4.28 lib/active_scaffold/extensions/left_outer_joins.rb
active_scaffold-3.4.27 lib/active_scaffold/extensions/left_outer_joins.rb
active_scaffold-3.4.26 lib/active_scaffold/extensions/left_outer_joins.rb
active_scaffold-3.4.25 lib/active_scaffold/extensions/left_outer_joins.rb