Class: RailsAdmin::Config::Fields::Types::BelongsToAssociation

Inherits:
SingularAssociation show all
Defined in:
lib/rails_admin/config/fields/types/belongs_to_association.rb

Direct Known Subclasses

PolymorphicAssociation

Constant Summary

Constants inherited from Base

Base::NAMED_INSTANCE_VARIABLES

Instance Attribute Summary

Attributes inherited from Base

#abstract_model, #defined, #name, #order, #parent, #properties, #root, #section

Instance Method Summary collapse

Methods inherited from SingularAssociation

#collection, #form_value, #multiple?, #widget_options

Methods inherited from Association

#associated_model_config, #associated_model_limit, #associated_object_label_method, #associated_prepopulate_params, #associated_primary_key, #association, #collection, #dynamic_scope_relationships, #method_name, #multiple?, #polymorphic?, #value, #virtual?

Methods inherited from Base

#association?, #eager_load_values, #editable?, #errors, #filter_options, #form_default_value, #form_value, #generic_field_help, #generic_help, #initialize, #inverse_of, #method_name, #optional, #optional=, #optional?, #parse_value, #sort_column, #type, #type_css_class, #value, #virtual?

Methods included from Inspectable

#inspect

Methods included from Groupable

#group

Methods included from Hideable

#hidden?, #hide, included, #show

Methods included from Configurable

#has_option?, included, #register_deprecated_instance_option, #register_instance_option

Methods included from Proxyable

#bindings, #bindings=, #with

Constructor Details

This class inherits a constructor from RailsAdmin::Config::Fields::Base

Instance Method Details

#parse_input(params) ⇒ Object



36
37
38
39
40
41
42
43
# File 'lib/rails_admin/config/fields/types/belongs_to_association.rb', line 36

def parse_input(params)
  return super if nested_form
  return unless params[method_name].present? && association.foreign_key.is_a?(Array)

  association.foreign_key.zip(RailsAdmin.config.composite_keys_serializer.deserialize(params.delete(method_name))).each do |key, value|
    params[key] = value
  end
end

#selected_idObject



28
29
30
31
32
33
34
# File 'lib/rails_admin/config/fields/types/belongs_to_association.rb', line 28

def selected_id
  if association.foreign_key.is_a?(Array)
    format_key(association.foreign_key.map { |attribute| bindings[:object].safe_send(attribute) })
  else
    bindings[:object].safe_send(association.key_accessor)
  end
end