Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fix row table projections when all projections are aliased.

  • Loading branch information...
commit 70f06d207e6fc0ea357e383dbc9f1aec6f918e3e 1 parent 226e6fe
@metaskills metaskills authored
View
16 lib/arel/visitors/sqlserver.rb
@@ -200,6 +200,13 @@ def single_distinct_select_statement?(o)
((first_prjn.respond_to?(:distinct) && first_prjn.distinct) || first_prjn.include?('DISTINCT'))
end
+ def all_projections_aliased_in_select_statement?(o)
+ projections = o.cores.first.projections
+ projections.all? do |x|
+ x.split(',').all? { |y| y.include?(' AS ') }
+ end
+ end
+
def function_select_statement?(o)
core = o.cores.first
core.projections.any? { |x| Arel::Nodes::Function === x }
@@ -248,11 +255,10 @@ def rowtable_projections(o)
p.strip!
end
end
- elsif false # join_in_select_statement?(o) && all_select_clauses_aliased?
- raise 'TODO: join_in_select_statement?(o) && all_select_clauses_aliased?'
- # relation.select_clauses.map do |sc|
- # sc.split(',').map { |c| c.split(' AS ').last.strip }.join(', ')
- # end
+ elsif join_in_select_statement?(o) && all_projections_aliased_in_select_statement?(o)
+ core.projections.map do |x|
+ Arel::Nodes::SqlLiteral.new x.split(',').map{ |y| y.split(' AS ').last.strip }.join(', ')
+ end
elsif function_select_statement?(o)
[Arel.star]
else
View
5 test/cases/scratch_test_sqlserver.rb
@@ -26,8 +26,9 @@ class ScratchTestSqlserver < ActiveRecord::TestCase
:developers, :projects, :developers_projects
should 'pass' do
- posts = Post.count(:all, :include => [ :author, :comments ], :limit => 2, :offset => 10, :conditions => [ "authors.name = ?", 'David' ])
- assert_equal 0, posts
+ comments = Comment.find(:all, :include => :post, :limit => 3, :offset => 2, :order => 'comments.id')
+ assert_equal 3, comments.length
+ assert_equal [3,5,6], comments.collect { |c| c.id }
end
Please sign in to comment.
Something went wrong with that request. Please try again.