Class: Uchi::Field::BelongsTo
- Inherits:
-
Uchi::Field
- Object
- Uchi::Field
- Uchi::Field::BelongsTo
- Defined in:
- app/components/uchi/field/belongs_to.rb
Defined Under Namespace
Constant Summary collapse
- DEFAULT_COLLECTION_QUERY =
->(query) { query }.freeze
Constants included from Configuration
Instance Attribute Summary
Attributes inherited from Uchi::Field
Instance Method Summary collapse
-
#collection_query(query_proc = Configuration::Unset) ⇒ self, Proc
Sets or gets a custom query for filtering the collection of associated records.
- #group_as(_action) ⇒ Object
-
#initialize(name) ⇒ BelongsTo
constructor
A new instance of BelongsTo.
- #param_key ⇒ Object
Methods inherited from Uchi::Field
#column_name, #edit_component, #edit_component_class, #index_component, #index_component_class, #permitted_param, #show_component, #show_component_class, #value
Methods included from Configuration
#on, #reader, #searchable, #searchable?, #sortable, #sortable?
Constructor Details
#initialize(name) ⇒ BelongsTo
Returns a new instance of BelongsTo.
72 73 74 75 |
# File 'app/components/uchi/field/belongs_to.rb', line 72 def initialize(name) super @collection_query = DEFAULT_COLLECTION_QUERY end |
Instance Method Details
#collection_query(query_proc = Configuration::Unset) ⇒ self, Proc
Sets or gets a custom query for filtering the collection of associated records.
When called with an argument, sets the query and returns self for chaining. When called without arguments, returns the current query.
94 95 96 97 98 99 |
# File 'app/components/uchi/field/belongs_to.rb', line 94 def collection_query(query_proc = Configuration::Unset) return @collection_query if query_proc == Configuration::Unset @collection_query = query_proc self end |
#group_as(_action) ⇒ Object
101 102 103 |
# File 'app/components/uchi/field/belongs_to.rb', line 101 def group_as(_action) :attributes end |
#param_key ⇒ Object
105 106 107 108 109 |
# File 'app/components/uchi/field/belongs_to.rb', line 105 def param_key # TODO: This is too naive. We need to match this to the actual foreign # key of the model. :"#{name}_id" end |