Class: Uchi::Field::BelongsTo::Edit

Inherits:
Uchi::Field::Base::Edit show all
Includes:
Helpers
Defined in:
app/components/uchi/field/belongs_to.rb

Instance Attribute Summary

Attributes inherited from Uchi::Field::Base::Edit

#form, #hint, #label

Attributes inherited from Uchi::Field::Base::Component

#field, #record, #repository

Instance Method Summary collapse

Methods included from Helpers

#associated_record, #label_for_associated_record

Methods inherited from Uchi::Field::Base::Edit

#initialize

Methods inherited from Uchi::Field::Base::Component

#initialize, #value

Constructor Details

This class inherits a constructor from Uchi::Field::Base::Edit

Instance Method Details

#associated_repositoryObject



42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'app/components/uchi/field/belongs_to.rb', line 42

def associated_repository
  @associated_repository ||= begin
    model = if reflection.polymorphic?
      associated_record&.class
    else
      reflection.klass
    end

    return nil if model.nil?

    repository_class = Uchi::Repository.for_model(model)
    repository_class.new
  end
end

#attribute_nameObject



57
58
59
# File 'app/components/uchi/field/belongs_to.rb', line 57

def attribute_name
  reflection.foreign_key
end

#dom_id_for_filter_query_inputObject



61
62
63
# File 'app/components/uchi/field/belongs_to.rb', line 61

def dom_id_for_filter_query_input
  "#{form.object_name}_#{attribute_name}_belongs_to_filter_query"
end

#dom_id_for_toggleObject



65
66
67
# File 'app/components/uchi/field/belongs_to.rb', line 65

def dom_id_for_toggle
  "#{form.object_name}_#{attribute_name}_belongs_to_toggle"
end

#record_title(record) ⇒ Object



69
70
71
72
73
# File 'app/components/uchi/field/belongs_to.rb', line 69

def record_title(record)
  return "" if record.nil?

  associated_repository.title(record)
end