Sha256: db01078c286c48ec9ac24b3145471822c2054ae2fb5cf4bcb8cfd460a9fa4f69

Contents?: true

Size: 870 Bytes

Versions: 13

Compression:

Stored size: 870 Bytes

Contents

require_relative "associative"

module Administrate
  module Field
    class BelongsTo < Associative
      def self.permitted_attribute(attr, _options = nil)
        :"#{attr}_id"
      end

      def permitted_attribute
        foreign_key
      end

      def associated_resource_options
        [nil] + candidate_resources.map do |resource|
          [display_candidate_resource(resource), resource.send(primary_key)]
        end
      end

      def selected_option
        data && data.send(primary_key)
      end

      private

      def candidate_resources
        scope = options[:scope] ? options[:scope].call : associated_class.all

        order = options.delete(:order)
        order ? scope.reorder(order) : scope
      end

      def display_candidate_resource(resource)
        associated_dashboard.display_resource(resource)
      end
    end
  end
end

Version data entries

13 entries across 13 versions & 3 rubygems

Version Path
administrate-0.14.0 lib/administrate/field/belongs_to.rb
viniBaxterDesk-22.0.0 lib/administrate/field/belongs_to.rb
viniBaxterDesk-0.21.0 lib/administrate/field/belongs_to.rb
viniBaxterDesk-0.20.0 lib/administrate/field/belongs_to.rb
viniBaxterDesk-0.14.0 lib/administrate/field/belongs_to.rb
viniBaxterDesk-0.13.2 lib/administrate/field/belongs_to.rb
viniBaxterDesk-0.13.1 lib/administrate/field/belongs_to.rb
administrate-0.13.0 lib/administrate/field/belongs_to.rb
administrate-0.12.0 lib/administrate/field/belongs_to.rb
administrate-0.11.0 lib/administrate/field/belongs_to.rb
semantic-administrate-0.10.1 lib/administrate/field/belongs_to.rb
semantic-administrate-0.10.0 lib/administrate/field/belongs_to.rb
administrate-0.10.0 lib/administrate/field/belongs_to.rb