Class: CrudComponents::Fields::HasManyField
- Defined in:
- lib/crud_components/fields/has_many_field.rb
Overview
has_many / habtm: truncated list of links (“a, b +3 more”). No derived filter or sort; opt in with ‘filter like: :assoc` (delegation).
Constant Summary
Constants inherited from Base
Instance Attribute Summary
Attributes inherited from Base
#facets, #model, #name, #options
Instance Method Summary collapse
-
#collection_link_target ⇒ Object
The index a “+n more” / list link points at: the nested route under the owner if it resolves, else the target’s index filtered by the owner.
- #default_editable? ⇒ Boolean
- #default_renderer ⇒ Object
-
#eager_load ⇒ Object
Load the association, nesting each target’s identity_preloads (+ this column’s ‘preload:`) so rendering the list’s labels never N+1s.
- #form_choices ⇒ Object
- #form_control ⇒ Object
-
#group_model ⇒ Object
Picker grouping: a has_many/habtm column anchors its target’s group, so ‘authors`, `authors.name` and `authors.email` all sit under “Author”.
-
#habtm? ⇒ Boolean
── forms ──────────────────────────────────────────────────────────── Editable only for habtm (and simple has_many) via the *_ids setter — reassigning ids is safe; nested attributes are out of scope.
- #ids_method ⇒ Object
- #permit_param ⇒ Object
- #reflection ⇒ Object
- #target ⇒ Object
- #target_structure ⇒ Object
Methods inherited from Base
#apply_derived_filter, #apply_filter, #apply_filter_facet, #apply_sort, #column, #custom_header?, #declared_preloads, #derived_filter_control, #derived_filterable?, #derived_sortable?, #editable?, #editable_permitted?, #filter_choices, #filter_control, #filter_facet, #filter_includes_null?, #filterable?, #form_partial, #group_label, #header, #header_actions, #human_name, #initialize, #nullable?, #permitted?, #picker_label, #range_filter?, #render_block, #renderer, #renderer_options, #sort_facet, #sortable?, #value
Constructor Details
This class inherits a constructor from CrudComponents::Fields::Base
Instance Method Details
#collection_link_target ⇒ Object
The index a “+n more” / list link points at: the nested route under the owner if it resolves, else the target’s index filtered by the owner. Resolved in the view (RouteResolver); here we just expose the association so the renderer can build it.
31 |
# File 'lib/crud_components/fields/has_many_field.rb', line 31 def collection_link_target = target |
#default_editable? ⇒ Boolean
37 |
# File 'lib/crud_components/fields/has_many_field.rb', line 37 def default_editable? = habtm? |
#default_renderer ⇒ Object
6 |
# File 'lib/crud_components/fields/has_many_field.rb', line 6 def default_renderer = :association_list |
#eager_load ⇒ Object
Load the association, nesting each target’s identity_preloads (+ this column’s ‘preload:`) so rendering the list’s labels never N+1s.
22 23 24 25 |
# File 'lib/crud_components/fields/has_many_field.rb', line 22 def eager_load nested = (target_structure.identity_preloads + declared_preloads).uniq [nested.empty? ? name : { name => nested }] end |
#form_choices ⇒ Object
42 43 44 45 |
# File 'lib/crud_components/fields/has_many_field.rb', line 42 def form_choices structure = target_structure target.all.map { |record| [structure.label_for(record).to_s, record.id] }.sort_by(&:first) end |
#form_control ⇒ Object
38 |
# File 'lib/crud_components/fields/has_many_field.rb', line 38 def form_control = :habtm |
#group_model ⇒ Object
Picker grouping: a has_many/habtm column anchors its target’s group, so ‘authors`, `authors.name` and `authors.email` all sit under “Author”.
18 |
# File 'lib/crud_components/fields/has_many_field.rb', line 18 def group_model = target |
#habtm? ⇒ Boolean
── forms ────────────────────────────────────────────────────────────Editable only for habtm (and simple has_many) via the *_ids setter —reassigning ids is safe; nested attributes are out of scope.
36 |
# File 'lib/crud_components/fields/has_many_field.rb', line 36 def habtm? = reflection.macro == :has_and_belongs_to_many |
#ids_method ⇒ Object
39 |
# File 'lib/crud_components/fields/has_many_field.rb', line 39 def ids_method = "#{name.to_s.singularize}_ids".to_sym |
#permit_param ⇒ Object
40 |
# File 'lib/crud_components/fields/has_many_field.rb', line 40 def permit_param = { ids_method => [] } |
#reflection ⇒ Object
8 9 10 |
# File 'lib/crud_components/fields/has_many_field.rb', line 8 def reflection @reflection ||= model.reflect_on_association(name) end |
#target ⇒ Object
12 13 14 |
# File 'lib/crud_components/fields/has_many_field.rb', line 12 def target reflection.klass end |