Sha256: 1739b671664a9f47b08eb8e9175e80a89f6014d401ac3a710941e6005b1ca588

Contents?: true

Size: 975 Bytes

Versions: 19

Compression:

Stored size: 975 Bytes

Contents

# Add support for :scope => :my_scope to associations

module ActiveRecord
  module Associations
    module ThroughAssociationScope # No such module in ActiveRecord any more - there is only ThroughAssociation

      def construct_scope_with_scope
        s = construct_scope_without_scope
        s[:find][:scope] = @reflection.options[:scope]
        s
      end
      alias_method_chain :construct_scope, :scope

      end
    end if false # DISABLED Getting Rails 3.1 working

  module SpawnMethods

    def apply_finder_options_with_scope(options)
      scopes = []
      Array.wrap(options.delete(:scope)).each do |s|
        if s.is_a?(Hash)
          s.each_pair{|k,v| scopes << [k,v] }
        else
          scopes << [s]
        end
      end
      relation = apply_finder_options_without_scope(options)
      return relation if scopes.empty?
      scopes.inject(relation) {|r, s| r.send *s }
    end
    alias_method_chain :apply_finder_options, :scope

  end
end

Version data entries

19 entries across 19 versions & 1 rubygems

Version Path
hobo-2.0.1 lib/hobo/extensions/active_record/associations/scope.rb
hobo-2.0.0 lib/hobo/extensions/active_record/associations/scope.rb
hobo-2.0.0.pre10 lib/hobo/extensions/active_record/associations/scope.rb
hobo-2.0.0.pre9 lib/hobo/extensions/active_record/associations/scope.rb
hobo-2.0.0.pre8 lib/hobo/extensions/active_record/associations/scope.rb
hobo-2.0.0.pre7 lib/hobo/extensions/active_record/associations/scope.rb
hobo-2.0.0.pre6 lib/hobo/extensions/active_record/associations/scope.rb
hobo-2.0.0.pre5 lib/hobo/extensions/active_record/associations/scope.rb
hobo-2.0.0.pre4 lib/hobo/extensions/active_record/associations/scope.rb
hobo-2.0.0.pre3 lib/hobo/extensions/active_record/associations/scope.rb
hobo-2.0.0.pre2 lib/hobo/extensions/active_record/associations/scope.rb
hobo-2.0.0.pre1 lib/hobo/extensions/active_record/associations/scope.rb
hobo-1.4.0.pre8 lib/hobo/extensions/active_record/associations/scope.rb
hobo-1.4.0.pre7 lib/hobo/extensions/active_record/associations/scope.rb
hobo-1.4.0.pre6 lib/hobo/extensions/active_record/associations/scope.rb
hobo-1.4.0.pre5 lib/hobo/extensions/active_record/associations/scope.rb
hobo-1.4.0.pre4 lib/hobo/extensions/active_record/associations/scope.rb
hobo-1.4.0.pre3 lib/hobo/extensions/active_record/associations/scope.rb
hobo-1.4.0.pre2 lib/hobo/extensions/active_record/associations/scope.rb