aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/associations.rb
diff options
context:
space:
mode:
authorEmilio Tagua <miloops@gmail.com>2009-07-14 23:00:08 -0300
committerEmilio Tagua <miloops@gmail.com>2009-07-14 23:00:08 -0300
commit634f6713ee15c6fd958bafc7a3422acac2e3343f (patch)
tree0df11ceb12f9911ad16c950802af1e5874c89ab4 /activerecord/lib/active_record/associations.rb
parentfb46d00fdfa724dc0c252a46ec13c4ee4cda4708 (diff)
parent40b387580ff251e06632fbcc87c2a78c027a6b27 (diff)
downloadrails-634f6713ee15c6fd958bafc7a3422acac2e3343f.tar.gz
rails-634f6713ee15c6fd958bafc7a3422acac2e3343f.tar.bz2
rails-634f6713ee15c6fd958bafc7a3422acac2e3343f.zip
Merge commit 'rails/master'
Diffstat (limited to 'activerecord/lib/active_record/associations.rb')
-rwxr-xr-xactiverecord/lib/active_record/associations.rb9
1 files changed, 8 insertions, 1 deletions
diff --git a/activerecord/lib/active_record/associations.rb b/activerecord/lib/active_record/associations.rb
index 97fdd9b1ba..31d3a89b9d 100755
--- a/activerecord/lib/active_record/associations.rb
+++ b/activerecord/lib/active_record/associations.rb
@@ -1273,9 +1273,16 @@ module ActiveRecord
if send(reflection.name).loaded? || reflection.options[:finder_sql]
send(reflection.name).map(&:id)
else
- send(reflection.name).all(:select => "#{reflection.quoted_table_name}.#{reflection.klass.primary_key}").map(&:id)
+ if reflection.through_reflection && reflection.source_reflection.belongs_to?
+ through = reflection.through_reflection
+ primary_key = reflection.source_reflection.primary_key_name
+ send(through.name).all(:select => "DISTINCT #{through.quoted_table_name}.#{primary_key}").map!(&:"#{primary_key}")
+ else
+ send(reflection.name).all(:select => "#{reflection.quoted_table_name}.#{reflection.klass.primary_key}").map!(&:id)
+ end
end
end
+
end
def collection_accessor_methods(reflection, association_proxy_class, writer = true)