From 9c1c551f25577c01624b23bc53139c60a4fc451b Mon Sep 17 00:00:00 2001 From: Raimonds Simanovskis Date: Tue, 4 Jan 2011 17:06:33 +0200 Subject: 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. --- .../active_record/associations/has_and_belongs_to_many_association.rb | 3 ++- activerecord/lib/active_record/relation/finder_methods.rb | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) (limited to 'activerecord/lib') 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 -- cgit v1.2.3