aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib
diff options
context:
space:
mode:
authorRafael Mendonça França <rafaelmfranca@gmail.com>2014-10-15 18:44:11 -0300
committerRafael Mendonça França <rafaelmfranca@gmail.com>2014-10-15 18:44:11 -0300
commit1130b5d38904a19966508154023fca5df7eecaab (patch)
treee26dee6ecebf7f820682a1fefba8cfc447483e75 /activerecord/lib
parentba769cc4836cd909fd6dd659220790d9b98e4072 (diff)
parentf260f9cd294f33301a4971e44a25cccdd95273d6 (diff)
downloadrails-1130b5d38904a19966508154023fca5df7eecaab.tar.gz
rails-1130b5d38904a19966508154023fca5df7eecaab.tar.bz2
rails-1130b5d38904a19966508154023fca5df7eecaab.zip
Merge pull request #17267 from rebyn/master
Raise an error for has_one associations which try to go :through a polymorphic association
Diffstat (limited to 'activerecord/lib')
-rw-r--r--activerecord/lib/active_record/associations.rb6
-rw-r--r--activerecord/lib/active_record/reflection.rb1
2 files changed, 7 insertions, 0 deletions
diff --git a/activerecord/lib/active_record/associations.rb b/activerecord/lib/active_record/associations.rb
index 12ca3a48a9..8911506694 100644
--- a/activerecord/lib/active_record/associations.rb
+++ b/activerecord/lib/active_record/associations.rb
@@ -46,6 +46,12 @@ module ActiveRecord
end
end
+ class HasOneAssociationPolymorphicThroughError < ActiveRecordError #:nodoc:
+ def initialize(owner_class_name, reflection)
+ super("Cannot have a has_one :through association '#{owner_class_name}##{reflection.name}' which goes through the polymorphic association '#{owner_class_name}##{reflection.through_reflection.name}'.")
+ end
+ end
+
class HasManyThroughSourceAssociationNotFoundError < ActiveRecordError #:nodoc:
def initialize(reflection)
through_reflection = reflection.through_reflection
diff --git a/activerecord/lib/active_record/reflection.rb b/activerecord/lib/active_record/reflection.rb
index 6b5a592ee5..cff70511f5 100644
--- a/activerecord/lib/active_record/reflection.rb
+++ b/activerecord/lib/active_record/reflection.rb
@@ -821,6 +821,7 @@ module ActiveRecord
end
if through_reflection.polymorphic?
+ raise HasOneAssociationPolymorphicThroughError.new(active_record.name, self) if has_one?
raise HasManyThroughAssociationPolymorphicThroughError.new(active_record.name, self)
end