Class: Uchi::Field::HasMany
- Inherits:
-
Uchi::Field
- Object
- Uchi::Field
- Uchi::Field::HasMany
- Defined in:
- app/components/uchi/field/has_many.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) ⇒ HasMany
constructor
A new instance of HasMany.
- #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) ⇒ HasMany
Returns a new instance of HasMany.
61 62 63 64 |
# File 'app/components/uchi/field/has_many.rb', line 61 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.
83 84 85 86 87 88 |
# File 'app/components/uchi/field/has_many.rb', line 83 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
90 91 92 |
# File 'app/components/uchi/field/has_many.rb', line 90 def group_as(_action) :associations end |
#param_key ⇒ Object
94 95 96 97 98 |
# File 'app/components/uchi/field/has_many.rb', line 94 def param_key # TODO: This is too naive. We need to match this to the actual foreign # key of the model. :"#{name}_id" end |