diff options
author | George Claghorn <george@basecamp.com> | 2018-07-07 17:04:47 -0400 |
---|---|---|
committer | George Claghorn <george@basecamp.com> | 2018-07-07 17:09:31 -0400 |
commit | 03afddd2eb0fb56716a8a9caa4456807706ce791 (patch) | |
tree | 8382eba357d69f6d2acf776582c2113ed60c71c9 /activestorage/lib/active_storage | |
parent | 13c66d4626707fcc6c67ec6b197bb1e0be317b84 (diff) | |
download | rails-03afddd2eb0fb56716a8a9caa4456807706ce791.tar.gz rails-03afddd2eb0fb56716a8a9caa4456807706ce791.tar.bz2 rails-03afddd2eb0fb56716a8a9caa4456807706ce791.zip |
Fix that models can clobber each others' attachment reflections
Consider the following model definitions:
class User < ApplicationRecord
has_one_attached :avatar
end
class Group < ApplicationRecord
has_one_attached :avatar
end
If you attempt to reflect on the User model's avatar attachment via User.reflect_on_attachment, you could receive a reflection for the Group model's avatar attachment. Fix this by ensuring that each model class uses its own Hash object to track attachment reflections.
Diffstat (limited to 'activestorage/lib/active_storage')
-rw-r--r-- | activestorage/lib/active_storage/reflection.rb | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/activestorage/lib/active_storage/reflection.rb b/activestorage/lib/active_storage/reflection.rb index 04a1b20882..ce248c88b5 100644 --- a/activestorage/lib/active_storage/reflection.rb +++ b/activestorage/lib/active_storage/reflection.rb @@ -19,8 +19,8 @@ module ActiveStorage end module ReflectionExtension # :nodoc: - def add_attachment_reflection(ar, name, reflection) - ar.attachment_reflections.merge!(name.to_s => reflection) + def add_attachment_reflection(model, name, reflection) + model.attachment_reflections = model.attachment_reflections.merge(name.to_s => reflection) end private |