Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extract primary_key to AbstractReflection #30208

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 4 additions & 8 deletions activerecord/lib/active_record/reflection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,10 @@ def predicate_builder(table)
def join_pk(_)
foreign_key
end

def primary_key(klass)
klass.primary_key || raise(UnknownPrimaryKey.new(klass))
end
end

# Base class for AggregateReflection and AssociationReflection. Objects of
Expand Down Expand Up @@ -697,10 +701,6 @@ def derive_foreign_key
def derive_join_table
ModelSchema.derive_join_table_name active_record.table_name, klass.table_name
end

def primary_key(klass)
klass.primary_key || raise(UnknownPrimaryKey.new(klass))
end
end

class HasManyReflection < AssociationReflection # :nodoc:
Expand Down Expand Up @@ -1024,10 +1024,6 @@ def collect_join_reflections(seed)
end
end

def primary_key(klass)
klass.primary_key || raise(UnknownPrimaryKey.new(klass))
end

def inverse_name; delegate_reflection.send(:inverse_name); end

def derive_class_name
Expand Down