diff options
author | Pratik Naik <pratiknaik@gmail.com> | 2008-10-04 17:41:27 +0100 |
---|---|---|
committer | Pratik Naik <pratiknaik@gmail.com> | 2008-10-04 17:49:39 +0100 |
commit | 4918e6de989a80bb2ae92183f1b4eb98c15b487f (patch) | |
tree | fe8842f0204f1bf4934efe7a02f7df192b0f263b /activerecord/lib/active_record/reflection.rb | |
parent | 25ca21ae21d49f06708357a5ce0670103ced2d58 (diff) | |
download | rails-4918e6de989a80bb2ae92183f1b4eb98c15b487f.tar.gz rails-4918e6de989a80bb2ae92183f1b4eb98c15b487f.tar.bz2 rails-4918e6de989a80bb2ae92183f1b4eb98c15b487f.zip |
Remove HasManyAssociationStrategy and move the logic to ActiveRecord::Reflection::ThroughReflection.
Diffstat (limited to 'activerecord/lib/active_record/reflection.rb')
-rw-r--r-- | activerecord/lib/active_record/reflection.rb | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/activerecord/lib/active_record/reflection.rb b/activerecord/lib/active_record/reflection.rb index 77d03493dc..dbff4f24d6 100644 --- a/activerecord/lib/active_record/reflection.rb +++ b/activerecord/lib/active_record/reflection.rb @@ -117,6 +117,11 @@ module ActiveRecord @sanitized_conditions ||= klass.send(:sanitize_sql, options[:conditions]) if options[:conditions] end + # Returns +true+ if +self+ is a +belongs_to+ reflection. + def belongs_to? + macro == :belongs_to + end + private def derive_class_name name.to_s.camelize @@ -200,6 +205,9 @@ module ActiveRecord false end + def through_reflection_primary_key_name + end + def source_reflection nil end @@ -212,7 +220,7 @@ module ActiveRecord end def derive_primary_key_name - if macro == :belongs_to + if belongs_to? "#{name}_id" elsif options[:as] "#{options[:as]}_id" @@ -281,6 +289,14 @@ module ActiveRecord end end + def through_reflection_primary_key + through_reflection.belongs_to? ? through_reflection.klass.primary_key : through_reflection.primary_key_name + end + + def through_reflection_primary_key_name + through_reflection.primary_key_name if through_reflection.belongs_to? + end + private def derive_class_name # get the class_name of the belongs_to association of the through reflection |