Class: ActiveRecord::Reflection::AssociationReflection
- Inherits:
-
MacroReflection
- Object
- MacroReflection
- ActiveRecord::Reflection::AssociationReflection
- Defined in:
- lib/composite_primary_keys/reflection.rb
Direct Known Subclasses
Instance Method Summary collapse
Instance Method Details
#active_record_primary_key ⇒ Object
44 45 46 47 48 49 50 51 |
# File 'lib/composite_primary_keys/reflection.rb', line 44 def active_record_primary_key # CPK (Rails freezes the string returned in the expression that calculates PK here. But Rails uses the `-` method which is not available on Array for CPK, so we calculate it in one line and freeze it on the next) # @active_record_primary_key ||= -(options[:primary_key]&.to_s || primary_key(active_record)) @active_record_primary_key ||= begin pk = [:primary_key] || primary_key(active_record) pk.freeze end end |
#association_foreign_key ⇒ Object
38 39 40 41 42 |
# File 'lib/composite_primary_keys/reflection.rb', line 38 def association_foreign_key # CPK # @association_foreign_key ||= -(options[:association_foreign_key]&.to_s || class_name.foreign_key) @association_foreign_key ||= extract_keys([:association_foreign_key]) || class_name.foreign_key end |
#foreign_key ⇒ Object
32 33 34 35 36 |
# File 'lib/composite_primary_keys/reflection.rb', line 32 def foreign_key # CPK # @foreign_key ||= -(options[:foreign_key]&.to_s || derive_foreign_key) @foreign_key ||= extract_keys([:foreign_key]) || derive_foreign_key end |