diff options
author | Raimonds Simanovskis <raimonds.simanovskis@gmail.com> | 2011-01-04 17:06:33 +0200 |
---|---|---|
committer | Raimonds Simanovskis <raimonds.simanovskis@gmail.com> | 2011-01-04 17:06:33 +0200 |
commit | 9c1c551f25577c01624b23bc53139c60a4fc451b (patch) | |
tree | 5b2fc58fb944f3e84ba1cd6923361573c0f8f274 /activerecord | |
parent | 40afcade0dc1450e765a91fc15a6ac6d442c9826 (diff) | |
download | rails-9c1c551f25577c01624b23bc53139c60a4fc451b.tar.gz rails-9c1c551f25577c01624b23bc53139c60a4fc451b.tar.bz2 rails-9c1c551f25577c01624b23bc53139c60a4fc451b.zip |
Explicitly select * from has_and_belongs_to_many association tables, simplify exists? query
Previous version (after commit 3103296a61709e808aa89c3d37cf22bcdbc5a675) was generating wrong SQL for Oracle when calling exists? method on HABTM association.
Diffstat (limited to 'activerecord')
-rw-r--r-- | activerecord/lib/active_record/associations/has_and_belongs_to_many_association.rb | 3 | ||||
-rw-r--r-- | activerecord/lib/active_record/relation/finder_methods.rb | 2 |
2 files changed, 3 insertions, 2 deletions
diff --git a/activerecord/lib/active_record/associations/has_and_belongs_to_many_association.rb b/activerecord/lib/active_record/associations/has_and_belongs_to_many_association.rb index 1c237eda33..a4194defc2 100644 --- a/activerecord/lib/active_record/associations/has_and_belongs_to_many_association.rb +++ b/activerecord/lib/active_record/associations/has_and_belongs_to_many_association.rb @@ -83,7 +83,8 @@ module ActiveRecord super.merge( :joins => construct_joins, :readonly => ambiguous_select?(@reflection.options[:select]), - :select => @reflection.options[:select] || Arel.star + :select => @reflection.options[:select] || + Arel.sql("#{@reflection.quoted_table_name}.*, #{@owner.connection.quote_table_name @reflection.options[:join_table]}.*") ) end diff --git a/activerecord/lib/active_record/relation/finder_methods.rb b/activerecord/lib/active_record/relation/finder_methods.rb index 13f55319a7..8bbc47ab75 100644 --- a/activerecord/lib/active_record/relation/finder_methods.rb +++ b/activerecord/lib/active_record/relation/finder_methods.rb @@ -171,7 +171,7 @@ module ActiveRecord def exists?(id = nil) id = id.id if ActiveRecord::Base === id - relation = select(table[primary_key]).limit(1) + relation = select("1").limit(1) case id when Array, Hash |