Sha256: 3b7df0a0e14a1d8295e748c91227b7d96892f83223858bf7ae4bacfbd3bf32ff

Contents?: true

Size: 1 KB

Versions: 28

Compression:

Stored size: 1 KB

Contents

module ActiveFedora
  module Associations
    class AssociationScope #:nodoc:

      attr_reader :association
      
      delegate :klass, :owner, :reflection, :interpolate, :to => :association
      delegate :chain, :scope_chain, :options, :source_options, :active_record, :to => :reflection

      def initialize(association)
        @association = association
      end

      
      def scope
        scope = klass.unscoped
        add_constraints(scope)
      end

      private
      def add_constraints(scope)
        chain.each_with_index do |reflection, i|
          if reflection.source_macro == :belongs_to
          elsif reflection.source_macro == :has_and_belongs_to_many
          else
            scope = scope.where( ActiveFedora::SolrService.construct_query_for_rel(association.send(:find_predicate) => owner.internal_uri))
          end

          
          is_first_chain = i == 0
          klass = is_first_chain ? self.klass : reflection.klass
        end

        scope
      end

    end
  end
end

Version data entries

28 entries across 28 versions & 1 rubygems

Version Path
active-fedora-7.1.1 lib/active_fedora/associations/association_scope.rb
active-fedora-7.1.0 lib/active_fedora/associations/association_scope.rb
active-fedora-7.0.4 lib/active_fedora/associations/association_scope.rb
active-fedora-7.0.3 lib/active_fedora/associations/association_scope.rb
active-fedora-7.0.2 lib/active_fedora/associations/association_scope.rb
active-fedora-7.0.1 lib/active_fedora/associations/association_scope.rb
active-fedora-7.0.0 lib/active_fedora/associations/association_scope.rb
active-fedora-7.0.0.rc3 lib/active_fedora/associations/association_scope.rb