提交 8fe6b90e 编写于 作者: M Michael Koziarski

Fix .count for has_many associations with multi-line finder-sql. Closes #3540


git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@3450 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
上级 a14b59b4
*SVN*
* Make .count work for has_many associations with multi line finder sql [schoenm@earthlink.net]
* Add AR::Base.base_class for querying the ancestor AR::Base subclass [Jamis Buck]
* Allow configuration of the column used for optimistic locking [wilsonb@gmail.com]
......
......@@ -179,7 +179,8 @@ def construct_sql
if @reflection.options[:counter_sql]
@counter_sql = interpolate_sql(@reflection.options[:counter_sql])
elsif @reflection.options[:finder_sql]
@reflection.options[:counter_sql] = @reflection.options[:finder_sql].gsub(/SELECT (.*) FROM/i, "SELECT COUNT(*) FROM")
# replace the SELECT clause with COUNT(*), preserving any hints within /* ... */
@reflection.options[:counter_sql] = @reflection.options[:finder_sql].sub(/SELECT (\/\*.*?\*\/ )?(.*)\bFROM\b/im) { "SELECT #{$1}COUNT(*) FROM" }
@counter_sql = interpolate_sql(@reflection.options[:counter_sql])
else
@counter_sql = @finder_sql
......
......@@ -107,7 +107,8 @@ def construct_sql
if @reflection.options[:counter_sql]
@counter_sql = interpolate_sql(@reflection.options[:counter_sql])
elsif @reflection.options[:finder_sql]
@reflection.options[:counter_sql] = @reflection.options[:finder_sql].gsub(/SELECT (.*) FROM/i, "SELECT COUNT(*) FROM")
# replace the SELECT clause with COUNT(*), preserving any hints within /* ... */
@reflection.options[:counter_sql] = @reflection.options[:finder_sql].sub(/SELECT (\/\*.*?\*\/ )?(.*)\bFROM\b/im) { "SELECT #{$1}COUNT(*) FROM" }
@counter_sql = interpolate_sql(@reflection.options[:counter_sql])
else
@counter_sql = @finder_sql
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册