method
active_record_primary_key
v7.2.3 -
Show latest stable
- Class:
ActiveRecord::Reflection::AssociationReflection
active_record_primary_key()public
No documentation available.
# File activerecord/lib/active_record/reflection.rb, line 590
def active_record_primary_key
custom_primary_key = options[:primary_key]
@active_record_primary_key ||= if custom_primary_key
if custom_primary_key.is_a?(Array)
custom_primary_key.map { |pk| pk.to_s.freeze }.freeze
else
custom_primary_key.to_s.freeze
end
elsif active_record.has_query_constraints? || options[:query_constraints]
active_record.query_constraints_list
elsif active_record.composite_primary_key?
# If active_record has composite primary key of shape [:<tenant_key>, :id], infer primary_key as :id
primary_key = primary_key(active_record)
primary_key.include?("id") ? "id" : primary_key.freeze
else
primary_key(active_record).freeze
end
end