method

compute_primary_key

Importance_0
v8.0.0 - Show latest stable - 0 notes - Class: ActiveRecord::AutosaveAssociation
compute_primary_key(reflection, record) private

No documentation

This method has no description. You can help the Ruby on Rails community by adding new notes.

Hide source
# File activerecord/lib/active_record/autosave_association.rb, line 566
      def compute_primary_key(reflection, record)
        if primary_key_options = reflection.options[:primary_key]
          primary_key_options
        elsif reflection.options[:query_constraints] && (query_constraints = record.class.query_constraints_list)
          query_constraints
        elsif record.class.has_query_constraints? && !reflection.options[:foreign_key]
          record.class.query_constraints_list
        elsif record.class.composite_primary_key?
          # If record has composite primary key of shape [:<tenant_key>, :id], infer primary_key as :id
          primary_key = record.class.primary_key
          primary_key.include?("id") ? "id" : primary_key
        else
          record.class.primary_key
        end
      end
Register or log in to add new notes.