diff options
author | Rick Olson <technoweenie@gmail.com> | 2006-03-21 16:33:22 +0000 |
---|---|---|
committer | Rick Olson <technoweenie@gmail.com> | 2006-03-21 16:33:22 +0000 |
commit | 6fbf40823851c9f99c86c1287af0cfca725776e0 (patch) | |
tree | 1e1c31909175fdbc6c1e13bd0ab86b21dcb18592 /activerecord/lib | |
parent | c8470f8a5b74eefd498397a8effdf37b4dc28674 (diff) | |
download | rails-6fbf40823851c9f99c86c1287af0cfca725776e0.tar.gz rails-6fbf40823851c9f99c86c1287af0cfca725776e0.tar.bz2 rails-6fbf40823851c9f99c86c1287af0cfca725776e0.zip |
Allow overriding of find parameters in scoped has_many :through calls [Rick Olson]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@4007 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activerecord/lib')
-rw-r--r-- | activerecord/lib/active_record/associations/has_many_through_association.rb | 18 |
1 files changed, 9 insertions, 9 deletions
diff --git a/activerecord/lib/active_record/associations/has_many_through_association.rb b/activerecord/lib/active_record/associations/has_many_through_association.rb index 4e0b6f1c98..ae34885480 100644 --- a/activerecord/lib/active_record/associations/has_many_through_association.rb +++ b/activerecord/lib/active_record/associations/has_many_through_association.rb @@ -24,10 +24,10 @@ module ActiveRecord options[:order] = @reflection.options[:order] end - options[:select] = construct_select - options[:from] = construct_from - options[:joins] = construct_joins - options[:include] ||= @reflection.source_reflection.options[:include] + options[:select] = construct_select(options[:select]) + options[:from] ||= construct_from + options[:joins] = construct_joins(options[:joins]) + options[:include] = @reflection.source_reflection.options[:include] if options[:include].nil? merge_options_from_reflection!(options) @@ -84,11 +84,11 @@ module ActiveRecord @reflection.table_name end - def construct_select - selected = @reflection.options[:select] || "#{@reflection.table_name}.*" + def construct_select(custom_select = nil) + selected = custom_select || @reflection.options[:select] || "#{@reflection.table_name}.*" end - def construct_joins + def construct_joins(custom_joins = nil) if @reflection.through_reflection.options[:as] || @reflection.source_reflection.macro == :belongs_to reflection_primary_key = @reflection.klass.primary_key source_primary_key = @reflection.source_reflection.primary_key_name @@ -96,8 +96,8 @@ module ActiveRecord reflection_primary_key = @reflection.source_reflection.primary_key_name source_primary_key = @reflection.klass.primary_key end - - "INNER JOIN %s ON %s.%s = %s.%s #{@reflection.options[:joins]}" % [ + + "INNER JOIN %s ON %s.%s = %s.%s #{@reflection.options[:joins]} #{custom_joins}" % [ @reflection.through_reflection.table_name, @reflection.table_name, reflection_primary_key, @reflection.through_reflection.table_name, source_primary_key |