Module: LcpRuby::AssociationJoinColumn
- Defined in:
- lib/lcp_ruby/association_join_column.rb
Overview
Helper for resolving the join column on an association — i.e., the column whose value the form / search / cascading-select / page-parameter submits as the FK value.
For belongs_to with ‘primary_key:` set, the join column is that custom column on the target. Otherwise it is the target’s actual primary key column (usually “id”).
Used by Layer B consumers (form_helper, resources_controller, association_options_builder, view partials, page parameter resolver, virtual_columns/builder, import row processor, …) which bypass AR’s reflection and need the column name directly.
Class Method Summary collapse
-
.for(assoc, target_class = nil) ⇒ String
The column name to read off a target record.
Class Method Details
.for(assoc, target_class = nil) ⇒ String
Returns the column name to read off a target record.
21 22 23 24 25 26 |
# File 'lib/lcp_ruby/association_join_column.rb', line 21 def for(assoc, target_class = nil) return assoc.primary_key if assoc.primary_key.present? target_class ||= LcpRuby.registry.model_for(assoc.target_model) target_class.primary_key end |