diff options
author | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2012-04-25 17:17:49 +0000 |
---|---|---|
committer | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2012-04-25 17:17:49 +0000 |
commit | 5e57a1a9d9478162ac4f27ae96b2ccaf55a1aba7 (patch) | |
tree | 93e57765139714bd82dede475725516c448c0d55 /lib/redmine/core_ext | |
parent | 34e20c4373b7f5a20ab3a132feae3f70f21ec477 (diff) | |
download | redmine-5e57a1a9d9478162ac4f27ae96b2ccaf55a1aba7.tar.gz redmine-5e57a1a9d9478162ac4f27ae96b2ccaf55a1aba7.zip |
Merged rails-3.2 branch.
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@9528 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'lib/redmine/core_ext')
-rw-r--r-- | lib/redmine/core_ext/active_record.rb | 43 | ||||
-rw-r--r-- | lib/redmine/core_ext/string.rb | 4 |
2 files changed, 19 insertions, 28 deletions
diff --git a/lib/redmine/core_ext/active_record.rb b/lib/redmine/core_ext/active_record.rb index f881f90a5..5f84e144f 100644 --- a/lib/redmine/core_ext/active_record.rb +++ b/lib/redmine/core_ext/active_record.rb @@ -16,38 +16,25 @@ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. module ActiveRecord - class Base - def self.find_ids(options={}) - find_ids_with_associations(options) + module FinderMethods + def find_ids(*args) + find_ids_with_associations end - end - module Associations - module ClassMethods - def find_ids_with_associations(options = {}) - catch :invalid_query do - join_dependency = ActiveRecord::Associations::ClassMethods::JoinDependency.new(self, merge_includes(scope(:find, :include), options[:include]), options[:joins]) - return connection.select_values(construct_ids_finder_sql_with_included_associations(options, join_dependency)).map(&:to_i) - end + private + + def find_ids_with_associations + join_dependency = construct_join_dependency_for_association_find + relation = construct_relation_for_association_find_ids(join_dependency) + rows = connection.select_all(relation, 'SQL', relation.bind_values) + rows.map {|row| row["id"].to_i} + rescue ThrowResult [] - end - - def construct_ids_finder_sql_with_included_associations(options, join_dependency) - scope = scope(:find) - sql = "SELECT #{table_name}.id FROM #{(scope && scope[:from]) || options[:from] || quoted_table_name} " - sql << join_dependency.join_associations.collect{|join| join.association_join }.join - - add_joins!(sql, options[:joins], scope) - add_conditions!(sql, options[:conditions], scope) - add_limited_ids_condition!(sql, options, join_dependency) if !using_limitable_reflections?(join_dependency.reflections) && ((scope && scope[:limit]) || options[:limit]) - - add_group!(sql, options[:group], options[:having], scope) - add_order!(sql, options[:order], scope) - add_limit!(sql, options, scope) if using_limitable_reflections?(join_dependency.reflections) - add_lock!(sql, options, scope) + end - return sanitize_sql(sql) - end + def construct_relation_for_association_find_ids(join_dependency) + relation = except(:includes, :eager_load, :preload, :select).select("#{table_name}.id") + apply_join_dependency(relation, join_dependency) end end end diff --git a/lib/redmine/core_ext/string.rb b/lib/redmine/core_ext/string.rb index 2da5ffef9..c865284ac 100644 --- a/lib/redmine/core_ext/string.rb +++ b/lib/redmine/core_ext/string.rb @@ -4,4 +4,8 @@ require File.dirname(__FILE__) + '/string/inflections' class String #:nodoc: include Redmine::CoreExtensions::String::Conversions include Redmine::CoreExtensions::String::Inflections + + def is_binary_data? + ( self.count( "^ -~", "^\r\n" ).fdiv(self.size) > 0.3 || self.index( "\x00" ) ) unless empty? + end end |