aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/associations.rb
diff options
context:
space:
mode:
authorChris Holmes <tochrisholmes@gmail.com>2016-12-28 19:15:49 +0000
committerChris Holmes <tochrisholmes@gmail.com>2017-01-04 11:56:08 +0000
commitf8ab3ae18fbb5c4a4c9563296d0e7c528e754c42 (patch)
tree6cf3de11fe91e202811009251f1666b643c7100d /activerecord/lib/active_record/associations.rb
parentd304aefc91b485176b3d2fdc2f24147c1f78c132 (diff)
downloadrails-f8ab3ae18fbb5c4a4c9563296d0e7c528e754c42.tar.gz
rails-f8ab3ae18fbb5c4a4c9563296d0e7c528e754c42.tar.bz2
rails-f8ab3ae18fbb5c4a4c9563296d0e7c528e754c42.zip
Raise error when has_many through is defined before through association
https://github.com/rails/rails/issues/26834 This change raises an error if a has_many through association is defined before the through association.
Diffstat (limited to 'activerecord/lib/active_record/associations.rb')
-rw-r--r--activerecord/lib/active_record/associations.rb10
1 files changed, 10 insertions, 0 deletions
diff --git a/activerecord/lib/active_record/associations.rb b/activerecord/lib/active_record/associations.rb
index 1db5fc0dd1..c05a6c87df 100644
--- a/activerecord/lib/active_record/associations.rb
+++ b/activerecord/lib/active_record/associations.rb
@@ -97,6 +97,16 @@ module ActiveRecord
end
end
+ class HasManyThroughOrderError < ActiveRecordError #:nodoc:
+ def initialize(owner_class_name = nil, reflection = nil, through_reflection = nil)
+ if owner_class_name && reflection && through_reflection
+ super("Cannot have a has_many :through association '#{owner_class_name}##{reflection.name}' which goes through '#{owner_class_name}##{through_reflection.name}' before the through association is defined.")
+ else
+ super("Cannot have a has_many :through association before the through association is defined.")
+ end
+ end
+ end
+
class ThroughCantAssociateThroughHasOneOrManyReflection < ActiveRecordError #:nodoc:
def initialize(owner = nil, reflection = nil)
if owner && reflection