aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record
diff options
context:
space:
mode:
authorJon Leighton <j@jonathanleighton.com>2010-10-19 17:22:42 +0100
committerJon Leighton <j@jonathanleighton.com>2010-10-19 17:22:42 +0100
commit82b889f7d37249adaa606558d4c05356b3e84d9a (patch)
tree5ef73ccfadb32c90f66890aceb72a1ea80c50d4b /activerecord/lib/active_record
parent1f7415ab3a5b433ecfb0c10d66343a894d73914a (diff)
downloadrails-82b889f7d37249adaa606558d4c05356b3e84d9a.tar.gz
rails-82b889f7d37249adaa606558d4c05356b3e84d9a.tar.bz2
rails-82b889f7d37249adaa606558d4c05356b3e84d9a.zip
Add explicit tests for the nested through association changes in reflection.rb
Diffstat (limited to 'activerecord/lib/active_record')
-rw-r--r--activerecord/lib/active_record/reflection.rb15
1 files changed, 13 insertions, 2 deletions
diff --git a/activerecord/lib/active_record/reflection.rb b/activerecord/lib/active_record/reflection.rb
index 7ce2bbb8ae..3448cc506c 100644
--- a/activerecord/lib/active_record/reflection.rb
+++ b/activerecord/lib/active_record/reflection.rb
@@ -450,15 +450,26 @@ module ActiveRecord
end
end
+ # A through association is nested iff there would be more than one join table
def nested?
- through_reflection_chain.length > 2
+ through_reflection_chain.length > 2 ||
+ through_reflection.macro == :has_and_belongs_to_many
end
# We want to use the klass from this reflection, rather than just delegate straight to
# the source_reflection, because the source_reflection may be polymorphic. We still
# need to respect the source_reflection's :primary_key option, though.
def association_primary_key
- @association_primary_key ||= source_reflection.options[:primary_key] || klass.primary_key
+ @association_primary_key ||= begin
+ # Get the "actual" source reflection if the immediate source reflection has a
+ # source reflection itself
+ source_reflection = self.source_reflection
+ while source_reflection.source_reflection
+ source_reflection = source_reflection.source_reflection
+ end
+
+ source_reflection.options[:primary_key] || klass.primary_key
+ end
end
# Gets an array of possible <tt>:through</tt> source reflection names: