diff options
author | Xavier Noria <fxn@hashref.com> | 2010-07-30 02:35:24 +0200 |
---|---|---|
committer | Xavier Noria <fxn@hashref.com> | 2010-07-30 02:35:24 +0200 |
commit | ccd45618ed9a629c9535a5ff84ef5c238befa4ab (patch) | |
tree | 0a582bf695dce01240762d2b8516efde43bc3515 /activerecord/lib/active_record | |
parent | 3c3ff1377d17b584dd14d85c7cecab59ddff2679 (diff) | |
parent | 755af497555fde16db86f7e51f6462b0aca79b49 (diff) | |
download | rails-ccd45618ed9a629c9535a5ff84ef5c238befa4ab.tar.gz rails-ccd45618ed9a629c9535a5ff84ef5c238befa4ab.tar.bz2 rails-ccd45618ed9a629c9535a5ff84ef5c238befa4ab.zip |
Merge remote branch 'rails/master'
Diffstat (limited to 'activerecord/lib/active_record')
10 files changed, 29 insertions, 27 deletions
diff --git a/activerecord/lib/active_record/associations/association_collection.rb b/activerecord/lib/active_record/associations/association_collection.rb index 4ce3b34819..b5159eead3 100644 --- a/activerecord/lib/active_record/associations/association_collection.rb +++ b/activerecord/lib/active_record/associations/association_collection.rb @@ -422,7 +422,7 @@ module ActiveRecord match = DynamicFinderMatch.match(method) if match && match.creator? attributes = match.attribute_names - return send(:"find_by_#{attributes.join('and')}", *args) || create(Hash[attributes.zip(args)]) + return send(:"find_by_#{attributes.join('_and_')}", *args) || create(Hash[attributes.zip(args)]) end if @target.respond_to?(method) || (!@reflection.klass.respond_to?(method) && Class.respond_to?(method)) diff --git a/activerecord/lib/active_record/base.rb b/activerecord/lib/active_record/base.rb index 5898ec3732..391c287fe4 100644 --- a/activerecord/lib/active_record/base.rb +++ b/activerecord/lib/active_record/base.rb @@ -803,7 +803,7 @@ module ActiveRecord #:nodoc: end def arel_table - @arel_table ||= Arel::Table.new(table_name, :engine => arel_engine) + @arel_table ||= Arel::Table.new(table_name, arel_engine) end def arel_engine diff --git a/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb b/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb index 69a963c3d3..d8c92d0ad3 100644 --- a/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb +++ b/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb @@ -34,13 +34,11 @@ module ActiveRecord include QueryCache include ActiveSupport::Callbacks - attr_accessor :runtime define_callbacks :checkout, :checkin def initialize(connection, logger = nil) #:nodoc: @active = nil @connection, @logger = connection, logger - @runtime = 0 @query_cache_enabled = false @query_cache = {} @instrumenter = ActiveSupport::Notifications.instrumenter @@ -92,11 +90,6 @@ module ActiveRecord false end - def reset_runtime #:nodoc: - rt, @runtime = @runtime, 0 - rt - end - # QUOTING ================================================== # Override to return the quoted table name. Defaults to column quoting. diff --git a/activerecord/lib/active_record/log_subscriber.rb b/activerecord/lib/active_record/log_subscriber.rb index f7ae5587ed..c7ae12977a 100644 --- a/activerecord/lib/active_record/log_subscriber.rb +++ b/activerecord/lib/active_record/log_subscriber.rb @@ -1,13 +1,25 @@ module ActiveRecord class LogSubscriber < ActiveSupport::LogSubscriber + def self.runtime=(value) + Thread.current["active_record_sql_runtime"] = value + end + + def self.runtime + Thread.current["active_record_sql_runtime"] ||= 0 + end + + def self.reset_runtime + rt, self.runtime = runtime, 0 + rt + end + def initialize super @odd_or_even = false end def sql(event) - connection = ActiveRecord::Base.connection - connection.runtime += event.duration + self.class.runtime += event.duration return unless logger.debug? name = '%s (%.1fms)' % [event.payload[:name], event.duration] @@ -33,4 +45,4 @@ module ActiveRecord end end -ActiveRecord::LogSubscriber.attach_to :active_record +ActiveRecord::LogSubscriber.attach_to :active_record
\ No newline at end of file diff --git a/activerecord/lib/active_record/nested_attributes.rb b/activerecord/lib/active_record/nested_attributes.rb index cf8c5aaf84..e652296e2c 100644 --- a/activerecord/lib/active_record/nested_attributes.rb +++ b/activerecord/lib/active_record/nested_attributes.rb @@ -78,7 +78,7 @@ module ActiveRecord # member.avatar_attributes = { :id => '2', :_destroy => '1' } # member.avatar.marked_for_destruction? # => true # member.save - # member.reload.avatar #=> nil + # member.reload.avatar # => nil # # Note that the model will _not_ be destroyed until the parent is saved. # @@ -180,7 +180,7 @@ module ActiveRecord # # member.attributes = params['member'] # member.posts.detect { |p| p.id == 2 }.marked_for_destruction? # => true - # member.posts.length #=> 2 + # member.posts.length # => 2 # member.save # member.reload.posts.length # => 1 # diff --git a/activerecord/lib/active_record/railties/controller_runtime.rb b/activerecord/lib/active_record/railties/controller_runtime.rb index cf74fa1655..bc6ca936c0 100644 --- a/activerecord/lib/active_record/railties/controller_runtime.rb +++ b/activerecord/lib/active_record/railties/controller_runtime.rb @@ -11,10 +11,9 @@ module ActiveRecord def cleanup_view_runtime if ActiveRecord::Base.connected? - connection = ActiveRecord::Base.connection - db_rt_before_render = connection.reset_runtime + db_rt_before_render = ActiveRecord::LogSubscriber.reset_runtime runtime = super - db_rt_after_render = connection.reset_runtime + db_rt_after_render = ActiveRecord::LogSubscriber.reset_runtime self.db_runtime = db_rt_before_render + db_rt_after_render runtime - db_rt_after_render else diff --git a/activerecord/lib/active_record/relation.rb b/activerecord/lib/active_record/relation.rb index 86a210d2be..a8cea44c78 100644 --- a/activerecord/lib/active_record/relation.rb +++ b/activerecord/lib/active_record/relation.rb @@ -108,7 +108,7 @@ module ActiveRecord # ==== Example # # Comment.where(:post_id => 1).scoping do - # Comment.first #=> SELECT * FROM comments WHERE post_id = 1 + # Comment.first # SELECT * FROM comments WHERE post_id = 1 # end # # Please check unscoped if you want to remove all previous scopes (including diff --git a/activerecord/lib/active_record/relation/query_methods.rb b/activerecord/lib/active_record/relation/query_methods.rb index 0593897fa5..716e7275a5 100644 --- a/activerecord/lib/active_record/relation/query_methods.rb +++ b/activerecord/lib/active_record/relation/query_methods.rb @@ -47,9 +47,9 @@ module ActiveRecord clone.tap {|r| r.joins_values += args if args.present? } end - def where(*args) - value = build_where(*args) - clone.tap {|r| r.where_values += Array.wrap(value) if value.present? } + def where(opts, other = nil) + value = build_where(opts, other) + value ? clone.tap {|r| r.where_values += Array.wrap(value) } : clone end def having(*args) @@ -166,13 +166,10 @@ module ActiveRecord arel end - def build_where(*args) - return if args.blank? - - opts = args.first + def build_where(opts, other = nil) case opts when String, Array - @klass.send(:sanitize_sql, args.size > 1 ? args : opts) + @klass.send(:sanitize_sql, other ? [opts, other] : opts) when Hash attributes = @klass.send(:expand_hash_conditions_for_aggregates, opts) PredicateBuilder.new(table.engine).build_from_hash(attributes, table) diff --git a/activerecord/lib/active_record/session_store.rb b/activerecord/lib/active_record/session_store.rb index 766e63edc7..becde0fbfd 100644 --- a/activerecord/lib/active_record/session_store.rb +++ b/activerecord/lib/active_record/session_store.rb @@ -293,6 +293,7 @@ module ActiveRecord private def get_session(env, sid) Base.silence do + sid ||= generate_sid session = find_session(sid) env[SESSION_RECORD_KEY] = session [sid, session.data] diff --git a/activerecord/lib/active_record/version.rb b/activerecord/lib/active_record/version.rb index d18fed0131..a467ffa960 100644 --- a/activerecord/lib/active_record/version.rb +++ b/activerecord/lib/active_record/version.rb @@ -3,7 +3,7 @@ module ActiveRecord MAJOR = 3 MINOR = 0 TINY = 0 - BUILD = "beta4" + BUILD = "rc" STRING = [MAJOR, MINOR, TINY, BUILD].join('.') end |