Sha256: 772df2ef04e8ce5dab3e99a0c4b767e4d8c8cf1026b9869c9a1cf699e31336cf

Contents?: true

Size: 867 Bytes

Versions: 10

Compression:

Stored size: 867 Bytes

Contents

# frozen_string_literal: true

module EacRailsUtils
  module Models
    module TablelessAssociations
      module AssociationScopeExtension
        if ActiveRecord.version >= Gem::Version.new('5.0.0.beta')
          def add_constraints(scope, owner, association_klass, refl, chain_head, chain_tail) # rubocop:disable Metrics/ParameterLists
            if refl.options[:active_model]
              target_ids = refl.options[:target_ids]
              return scope.where(id: owner[target_ids])
            end

            super
          end
        else
          def add_constraints(scope, owner, assoc_klass, refl, tracker)
            if refl.options[:active_model]
              target_ids = refl.options[:target_ids]
              return scope.where(id: owner[target_ids])
            end

            super
          end
        end
      end
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
eac_rails_utils-0.25.0 lib/eac_rails_utils/models/tableless_associations/association_scope_extension.rb
eac_rails_utils-0.24.0 lib/eac_rails_utils/models/tableless_associations/association_scope_extension.rb
eac_rails_utils-0.23.4 lib/eac_rails_utils/models/tableless_associations/association_scope_extension.rb
eac_rails_utils-0.23.3 lib/eac_rails_utils/models/tableless_associations/association_scope_extension.rb
eac_rails_utils-0.23.2 lib/eac_rails_utils/models/tableless_associations/association_scope_extension.rb
eac_rails_utils-0.23.1 lib/eac_rails_utils/models/tableless_associations/association_scope_extension.rb
eac_rails_utils-0.23.0 lib/eac_rails_utils/models/tableless_associations/association_scope_extension.rb
eac_rails_utils-0.22.3 lib/eac_rails_utils/models/tableless_associations/association_scope_extension.rb
eac_rails_utils-0.22.2 lib/eac_rails_utils/models/tableless_associations/association_scope_extension.rb
eac_rails_utils-0.22.1 lib/eac_rails_utils/models/tableless_associations/association_scope_extension.rb