提交 8f84cdd0 编写于 作者: A Andrew White

Use inspect when writing the foreign key from the reflection

If we don't use inspect inside the class_eval block then the foreign key
is written without quotes causing us to fetch the foreign key value and
not the column name.
上级 249876b9
......@@ -68,11 +68,11 @@ def add_touch_callbacks(reflection)
def belongs_to_touch_after_save_or_destroy_for_#{name}
record = #{name}
foreign_key_field = #{reflection.foreign_key}
foreign_key_field = #{reflection.foreign_key.inspect}
if changed_attributes.key?(foreign_key_field)
reflection_klass = #{reflection.klass}
old_foreign_id = changed_attributes[foreign_key_field]
old_record = reflection_klass.where(foreign_key_field.to_sym => old_foreign_id).first
old_record = reflection_klass.where(foreign_key_field => old_foreign_id).first
if old_record
old_record.touch #{options[:touch].inspect if options[:touch] != true}
end
......
......@@ -192,6 +192,12 @@ def self.name; 'Toy'; end
old_pet.update_columns(updated_at: time)
new_pet.update_columns(updated_at: time)
old_pet.reload
new_pet.reload
assert_equal time, new_pet.updated_at
assert_equal time, old_pet.updated_at
toy1.pet = new_pet
toy1.save!
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册