Sha256: 2933606d0647491b0842b1738e3d4aa365bd2aeb7b0cafc994c35d1614bee6bf

Contents?: true

Size: 1.65 KB

Versions: 10

Compression:

Stored size: 1.65 KB

Contents

require 'rails_admin/config/fields/association'

module RailsAdmin
  module Config
    module Fields
      module Types
        class BelongsToAssociation < RailsAdmin::Config::Fields::Association
          RailsAdmin::Config::Fields::Types.register(self)

          register_instance_option :formatted_value do
            (o = value) && o.send(associated_model_config.object_label_method)
          end

          register_instance_option :sortable do
            @sortable ||= abstract_model.adapter_supports_joins? && associated_model_config.abstract_model.properties.collect(&:name).include?(associated_model_config.object_label_method) ? associated_model_config.object_label_method : {abstract_model.table_name => method_name}
          end

          register_instance_option :searchable do
            @searchable ||= associated_model_config.abstract_model.properties.collect(&:name).include?(associated_model_config.object_label_method) ? [associated_model_config.object_label_method, {abstract_model.model => method_name}] : {abstract_model.model => method_name}
          end

          register_instance_option :partial do
            nested_form ? :form_nested_one : :form_filtering_select
          end

          register_instance_option :inline_add do
            true
          end

          register_instance_option :inline_edit do
            true
          end

          def selected_id
            bindings[:object].send(foreign_key)
          end

          def method_name
            nested_form ? "#{name}_attributes".to_sym : association.foreign_key
          end

          def multiple?
            false
          end
        end
      end
    end
  end
end

Version data entries

10 entries across 10 versions & 2 rubygems

Version Path
rails_admin-1.0.0 lib/rails_admin/config/fields/types/belongs_to_association.rb
rails_admin-1.0.0.rc lib/rails_admin/config/fields/types/belongs_to_association.rb
rails_admin-0.8.1 lib/rails_admin/config/fields/types/belongs_to_association.rb
sc_core-0.0.7 test/dummy/vendor/bundle/ruby/2.2.0/gems/rails_admin-0.7.0/lib/rails_admin/config/fields/types/belongs_to_association.rb
rails_admin-0.7.0 lib/rails_admin/config/fields/types/belongs_to_association.rb
rails_admin-0.6.8 lib/rails_admin/config/fields/types/belongs_to_association.rb
rails_admin-0.6.7 lib/rails_admin/config/fields/types/belongs_to_association.rb
rails_admin-0.6.6 lib/rails_admin/config/fields/types/belongs_to_association.rb
rails_admin-0.6.5 lib/rails_admin/config/fields/types/belongs_to_association.rb
rails_admin-0.6.4 lib/rails_admin/config/fields/types/belongs_to_association.rb