1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Refactor delegating join_primary_key instead of join_keys and association_primary_key in TableMetadata

Because `join_primary_key` is called by `join_keys` and it is to
abstract calling `association_primary_key`.
This commit is contained in:
Ryuta Kamizono 2017-12-31 22:05:23 +09:00
parent 15b3275a29
commit 2955ee4198
4 changed files with 5 additions and 6 deletions

View file

@ -293,7 +293,7 @@ module ActiveRecord
Relation.create(klass, table, predicate_builder)
end
def join_primary_key(_)
def join_primary_key(*)
foreign_key
end
@ -722,7 +722,7 @@ module ActiveRecord
end
end
def join_primary_key(klass)
def join_primary_key(klass = nil)
polymorphic? ? association_primary_key(klass) : association_primary_key
end

View file

@ -30,7 +30,7 @@ module ActiveRecord
end
def primary_key
associated_table.association_join_keys.key
associated_table.association_join_primary_key
end
def convert_to_id(value)

View file

@ -29,7 +29,7 @@ module ActiveRecord
end
def primary_key(value)
associated_table.association_primary_key(base_class(value))
associated_table.association_join_primary_key(base_class(value))
end
def base_class(value)

View file

@ -2,8 +2,7 @@
module ActiveRecord
class TableMetadata # :nodoc:
delegate :foreign_type, :foreign_key, :join_keys, :join_foreign_key, to: :association, prefix: true
delegate :association_primary_key, to: :association
delegate :foreign_type, :foreign_key, :join_primary_key, :join_foreign_key, to: :association, prefix: true
def initialize(klass, arel_table, association = nil)
@klass = klass