Sha256: b258981b4b208d5ac4b9faa63160fe3e863d8224e04e375c525ed979255409f3

Contents?: true

Size: 852 Bytes

Versions: 17

Compression:

Stored size: 852 Bytes

Contents

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

module ActiveRecord
  module Associations
    module ThroughAssociationScope

      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

  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

17 entries across 17 versions & 1 rubygems

Version Path
hobo-1.3.3 lib/hobo/extensions/active_record/associations/scope.rb
hobo-1.3.2 lib/hobo/extensions/active_record/associations/scope.rb
hobo-1.3.1 lib/hobo/extensions/active_record/associations/scope.rb
hobo-1.3.0 lib/hobo/extensions/active_record/associations/scope.rb
hobo-1.3.0.RC4 lib/hobo/extensions/active_record/associations/scope.rb
hobo-1.3.0.RC3 lib/hobo/extensions/active_record/associations/scope.rb
hobo-1.3.0.RC2 lib/hobo/extensions/active_record/associations/scope.rb
hobo-1.3.0.RC1 lib/hobo/extensions/active_record/associations/scope.rb
hobo-1.3.0.RC lib/hobo/extensions/active_record/associations/scope.rb
hobo-1.3.0.pre31 lib/hobo/extensions/active_record/associations/scope.rb
hobo-1.3.0.pre29 lib/hobo/extensions/active_record/associations/scope.rb
hobo-1.3.0.pre28 lib/hobo/extensions/active_record/associations/scope.rb
hobo-1.3.0.pre27 lib/hobo/extensions/active_record/associations/scope.rb
hobo-1.3.0.pre26 lib/hobo/extensions/active_record/associations/scope.rb
hobo-1.3.0.pre25 lib/hobo/extensions/active_record/associations/scope.rb
hobo-1.3.0.pre24 lib/hobo/extensions/active_record/associations/scope.rb
hobo-1.3.0.pre23 lib/hobo/extensions/active_record/associations/scope.rb