提交 197364f8 编写于 作者: R Rafael Mendonça França

Merge pull request #15803 from sgrif/sg-column-in-associations

Don't rely on the column for type casting reflections
......@@ -55,9 +55,9 @@ def ids_reader
# Implements the ids writer method, e.g. foo.item_ids= for Foo.has_many :items
def ids_writer(ids)
pk_column = reflection.primary_key_column
pk_type = reflection.primary_key_type
ids = Array(ids).reject { |id| id.blank? }
ids.map! { |i| pk_column.type_cast_from_user(i) }
ids.map! { |i| pk_type.type_cast_from_user(i) }
replace(klass.find(ids).index_by { |r| r.id }.values_at(*ids))
end
......
......@@ -290,8 +290,8 @@ def foreign_key
@foreign_key ||= options[:foreign_key] || derive_foreign_key
end
def primary_key_column
klass.columns_hash[klass.primary_key]
def primary_key_type
klass.type_for_attribute(klass.primary_key)
end
def association_foreign_key
......
......@@ -48,7 +48,7 @@ def find_finder_class_for(record) #:nodoc:
def build_relation(klass, table, attribute, value) #:nodoc:
if reflection = klass._reflect_on_association(attribute)
attribute = reflection.foreign_key
value = value.attributes[reflection.primary_key_column.name] unless value.nil?
value = value.attributes[reflection.klass.primary_key] unless value.nil?
end
attribute_name = attribute.to_s
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册