From 4851ca9e13a4317342df02ae25b1929340523f7a Mon Sep 17 00:00:00 2001 From: Patrick Joyce Date: Sun, 21 Jun 2009 22:07:23 +0100 Subject: Generate proper :counter_sql from :finder_sql when there is a newline character immediately following 'SELECT' [#2118 state:resolved] Signed-off-by: Pratik Naik --- activerecord/test/models/company.rb | 4 ++++ activerecord/test/models/project.rb | 6 ++++++ 2 files changed, 10 insertions(+) (limited to 'activerecord/test/models') diff --git a/activerecord/test/models/company.rb b/activerecord/test/models/company.rb index 4c2514b0b3..840527ddeb 100644 --- a/activerecord/test/models/company.rb +++ b/activerecord/test/models/company.rb @@ -48,6 +48,10 @@ class Firm < Company has_many :clients_with_interpolated_conditions, :class_name => "Client", :conditions => 'rating > #{rating}' has_many :clients_like_ms_with_hash_conditions, :conditions => { :name => 'Microsoft' }, :class_name => "Client", :order => "id" has_many :clients_using_sql, :class_name => "Client", :finder_sql => 'SELECT * FROM companies WHERE client_of = #{id}' + has_many :clients_using_multiline_sql, :class_name => "Client", :finder_sql => ' + SELECT + companies.* + FROM companies WHERE companies.client_of = #{id}' has_many :clients_using_counter_sql, :class_name => "Client", :finder_sql => 'SELECT * FROM companies WHERE client_of = #{id}', :counter_sql => 'SELECT COUNT(*) FROM companies WHERE client_of = #{id}' diff --git a/activerecord/test/models/project.rb b/activerecord/test/models/project.rb index f25b2ddf77..422b12dc83 100644 --- a/activerecord/test/models/project.rb +++ b/activerecord/test/models/project.rb @@ -8,6 +8,12 @@ class Project < ActiveRecord::Base has_and_belongs_to_many :developers_named_david_with_hash_conditions, :class_name => "Developer", :conditions => { :name => 'David' }, :uniq => true has_and_belongs_to_many :salaried_developers, :class_name => "Developer", :conditions => "salary > 0" has_and_belongs_to_many :developers_with_finder_sql, :class_name => "Developer", :finder_sql => 'SELECT t.*, j.* FROM developers_projects j, developers t WHERE t.id = j.developer_id AND j.project_id = #{id} ORDER BY t.id' + has_and_belongs_to_many :developers_with_multiline_finder_sql, :class_name => "Developer", :finder_sql => ' + SELECT + t.*, j.* + FROM + developers_projects j, + developers t WHERE t.id = j.developer_id AND j.project_id = #{id} ORDER BY t.id' has_and_belongs_to_many :developers_by_sql, :class_name => "Developer", :delete_sql => "DELETE FROM developers_projects WHERE project_id = \#{id} AND developer_id = \#{record.id}" has_and_belongs_to_many :developers_with_callbacks, :class_name => "Developer", :before_add => Proc.new {|o, r| o.developers_log << "before_adding#{r.id || ''}"}, :after_add => Proc.new {|o, r| o.developers_log << "after_adding#{r.id || ''}"}, -- cgit v1.2.3