Sha256: db988ac28e5d229dd3a8007fd32cfec5d9046541edabb845cc23ebef028927f7

Contents?: true

Size: 1 KB

Versions: 9

Compression:

Stored size: 1 KB

Contents

# frozen_string_literal: true

require 'rails_admin/adapters/active_record'
require 'rails_admin/adapters/composite_primary_keys/association'

module RailsAdmin
  module Adapters
    module CompositePrimaryKeys
      include RailsAdmin::Adapters::ActiveRecord

      def get(id, scope = scoped)
        begin
          object = scope.find(id)
        rescue ::ActiveRecord::RecordNotFound
          return nil
        end

        object.extend(RailsAdmin::Adapters::ActiveRecord::ObjectExtension)
      end

      def associations
        model.reflect_on_all_associations.collect do |association|
          RailsAdmin::Adapters::CompositePrimaryKeys::Association.new(association, model)
        end
      end

    private

      def bulk_scope(scope, options)
        if primary_key.is_a? Array
          options[:bulk_ids].map do |id|
            scope.where(primary_key.zip(::CompositePrimaryKeys::CompositeKeys.parse(id)).to_h)
          end.reduce(&:or)
        else
          super
        end
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
rails_admin-3.2.0.beta lib/rails_admin/adapters/composite_primary_keys.rb
rails_admin-3.1.4 lib/rails_admin/adapters/composite_primary_keys.rb
rails_admin-3.1.3 lib/rails_admin/adapters/composite_primary_keys.rb
rails_admin-3.1.2 lib/rails_admin/adapters/composite_primary_keys.rb
rails_admin-3.1.1 lib/rails_admin/adapters/composite_primary_keys.rb
rails_admin-3.1.0 lib/rails_admin/adapters/composite_primary_keys.rb
rails_admin-3.1.0.rc2 lib/rails_admin/adapters/composite_primary_keys.rb
rails_admin-3.1.0.rc lib/rails_admin/adapters/composite_primary_keys.rb
rails_admin-3.1.0.beta lib/rails_admin/adapters/composite_primary_keys.rb