activerecord 3.0.0.rc → 3.0.0.rc2

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of activerecord might be problematic. Click here for more details.

Files changed (55) hide show
  1. data/CHANGELOG +6 -1
  2. data/README.rdoc +9 -9
  3. data/lib/active_record/aggregations.rb +64 -51
  4. data/lib/active_record/association_preload.rb +11 -9
  5. data/lib/active_record/associations.rb +300 -204
  6. data/lib/active_record/associations/association_collection.rb +7 -2
  7. data/lib/active_record/associations/belongs_to_association.rb +9 -5
  8. data/lib/active_record/associations/has_and_belongs_to_many_association.rb +7 -6
  9. data/lib/active_record/associations/has_many_association.rb +6 -6
  10. data/lib/active_record/associations/has_many_through_association.rb +4 -3
  11. data/lib/active_record/associations/has_one_association.rb +7 -7
  12. data/lib/active_record/attribute_methods/time_zone_conversion.rb +2 -1
  13. data/lib/active_record/attribute_methods/write.rb +2 -2
  14. data/lib/active_record/autosave_association.rb +54 -72
  15. data/lib/active_record/base.rb +167 -108
  16. data/lib/active_record/callbacks.rb +43 -35
  17. data/lib/active_record/connection_adapters/abstract/connection_pool.rb +8 -11
  18. data/lib/active_record/connection_adapters/abstract/database_limits.rb +1 -1
  19. data/lib/active_record/connection_adapters/abstract/query_cache.rb +0 -8
  20. data/lib/active_record/connection_adapters/abstract/quoting.rb +1 -1
  21. data/lib/active_record/connection_adapters/abstract/schema_definitions.rb +8 -6
  22. data/lib/active_record/connection_adapters/abstract/schema_statements.rb +5 -3
  23. data/lib/active_record/connection_adapters/mysql_adapter.rb +5 -1
  24. data/lib/active_record/connection_adapters/postgresql_adapter.rb +9 -5
  25. data/lib/active_record/connection_adapters/sqlite_adapter.rb +5 -5
  26. data/lib/active_record/dynamic_finder_match.rb +3 -3
  27. data/lib/active_record/dynamic_scope_match.rb +1 -1
  28. data/lib/active_record/errors.rb +9 -5
  29. data/lib/active_record/fixtures.rb +36 -22
  30. data/lib/active_record/locale/en.yml +2 -2
  31. data/lib/active_record/migration.rb +36 -36
  32. data/lib/active_record/named_scope.rb +23 -11
  33. data/lib/active_record/nested_attributes.rb +3 -3
  34. data/lib/active_record/observer.rb +3 -3
  35. data/lib/active_record/persistence.rb +44 -29
  36. data/lib/active_record/railtie.rb +5 -8
  37. data/lib/active_record/railties/databases.rake +1 -1
  38. data/lib/active_record/reflection.rb +52 -52
  39. data/lib/active_record/relation.rb +26 -19
  40. data/lib/active_record/relation/batches.rb +4 -4
  41. data/lib/active_record/relation/calculations.rb +58 -34
  42. data/lib/active_record/relation/finder_methods.rb +21 -12
  43. data/lib/active_record/relation/query_methods.rb +26 -31
  44. data/lib/active_record/relation/spawn_methods.rb +17 -5
  45. data/lib/active_record/schema.rb +1 -1
  46. data/lib/active_record/schema_dumper.rb +12 -12
  47. data/lib/active_record/serialization.rb +1 -1
  48. data/lib/active_record/serializers/xml_serializer.rb +1 -1
  49. data/lib/active_record/session_store.rb +9 -9
  50. data/lib/active_record/test_case.rb +2 -2
  51. data/lib/active_record/timestamp.rb +31 -32
  52. data/lib/active_record/validations/associated.rb +4 -3
  53. data/lib/active_record/validations/uniqueness.rb +15 -11
  54. data/lib/active_record/version.rb +1 -1
  55. metadata +17 -16
@@ -2,7 +2,7 @@ require 'active_support/core_ext/array/wrap'
2
2
 
3
3
  module ActiveRecord
4
4
  # = Active Record Callbacks
5
- #
5
+ #
6
6
  # Callbacks are hooks into the lifecycle of an Active Record object that allow you to trigger logic
7
7
  # before or after an alteration of the object state. This can be used to make sure that associated and
8
8
  # dependent objects are deleted when +destroy+ is called (by overwriting +before_destroy+) or to massage attributes
@@ -26,8 +26,8 @@ module ActiveRecord
26
26
  # <tt>after_rollback</tt>.
27
27
  #
28
28
  # That's a total of ten callbacks, which gives you immense power to react and prepare for each state in the
29
- # Active Record lifecycle. The sequence for calling <tt>Base#save</tt> for an existing record is similar, except that each
30
- # <tt>_on_create</tt> callback is replaced by the corresponding <tt>_on_update</tt> callback.
29
+ # Active Record lifecycle. The sequence for calling <tt>Base#save</tt> for an existing record is similar,
30
+ # except that each <tt>_on_create</tt> callback is replaced by the corresponding <tt>_on_update</tt> callback.
31
31
  #
32
32
  # Examples:
33
33
  # class CreditCard < ActiveRecord::Base
@@ -55,9 +55,9 @@ module ActiveRecord
55
55
  #
56
56
  # == Inheritable callback queues
57
57
  #
58
- # Besides the overwritable callback methods, it's also possible to register callbacks through the use of the callback macros.
59
- # Their main advantage is that the macros add behavior into a callback queue that is kept intact down through an inheritance
60
- # hierarchy. Example:
58
+ # Besides the overwritable callback methods, it's also possible to register callbacks through the
59
+ # use of the callback macros. Their main advantage is that the macros add behavior into a callback
60
+ # queue that is kept intact down through an inheritance hierarchy.
61
61
  #
62
62
  # class Topic < ActiveRecord::Base
63
63
  # before_destroy :destroy_author
@@ -67,9 +67,9 @@ module ActiveRecord
67
67
  # before_destroy :destroy_readers
68
68
  # end
69
69
  #
70
- # Now, when <tt>Topic#destroy</tt> is run only +destroy_author+ is called. When <tt>Reply#destroy</tt> is run, both +destroy_author+ and
71
- # +destroy_readers+ are called. Contrast this to the situation where we've implemented the save behavior through overwriteable
72
- # methods:
70
+ # Now, when <tt>Topic#destroy</tt> is run only +destroy_author+ is called. When <tt>Reply#destroy</tt> is
71
+ # run, both +destroy_author+ and +destroy_readers+ are called. Contrast this to the following situation
72
+ # where the +before_destroy+ methis is overriden:
73
73
  #
74
74
  # class Topic < ActiveRecord::Base
75
75
  # def before_destroy() destroy_author end
@@ -79,20 +79,21 @@ module ActiveRecord
79
79
  # def before_destroy() destroy_readers end
80
80
  # end
81
81
  #
82
- # In that case, <tt>Reply#destroy</tt> would only run +destroy_readers+ and _not_ +destroy_author+. So, use the callback macros when
83
- # you want to ensure that a certain callback is called for the entire hierarchy, and use the regular overwriteable methods
84
- # when you want to leave it up to each descendant to decide whether they want to call +super+ and trigger the inherited callbacks.
82
+ # In that case, <tt>Reply#destroy</tt> would only run +destroy_readers+ and _not_ +destroy_author+.
83
+ # So, use the callback macros when you want to ensure that a certain callback is called for the entire
84
+ # hierarchy, and use the regular overwriteable methods when you want to leave it up to each descendant
85
+ # to decide whether they want to call +super+ and trigger the inherited callbacks.
85
86
  #
86
- # *IMPORTANT:* In order for inheritance to work for the callback queues, you must specify the callbacks before specifying the
87
- # associations. Otherwise, you might trigger the loading of a child before the parent has registered the callbacks and they won't
88
- # be inherited.
87
+ # *IMPORTANT:* In order for inheritance to work for the callback queues, you must specify the
88
+ # callbacks before specifying the associations. Otherwise, you might trigger the loading of a
89
+ # child before the parent has registered the callbacks and they won't be inherited.
89
90
  #
90
91
  # == Types of callbacks
91
92
  #
92
93
  # There are four types of callbacks accepted by the callback macros: Method references (symbol), callback objects,
93
- # inline methods (using a proc), and inline eval methods (using a string). Method references and callback objects are the
94
- # recommended approaches, inline methods using a proc are sometimes appropriate (such as for creating mix-ins), and inline
95
- # eval methods are deprecated.
94
+ # inline methods (using a proc), and inline eval methods (using a string). Method references and callback objects
95
+ # are the recommended approaches, inline methods using a proc are sometimes appropriate (such as for
96
+ # creating mix-ins), and inline eval methods are deprecated.
96
97
  #
97
98
  # The method reference callbacks work by specifying a protected or private method available in the object, like this:
98
99
  #
@@ -169,15 +170,15 @@ module ActiveRecord
169
170
  # end
170
171
  # end
171
172
  #
172
- # The callback macros usually accept a symbol for the method they're supposed to run, but you can also pass a "method string",
173
- # which will then be evaluated within the binding of the callback. Example:
173
+ # The callback macros usually accept a symbol for the method they're supposed to run, but you can also
174
+ # pass a "method string", which will then be evaluated within the binding of the callback. Example:
174
175
  #
175
176
  # class Topic < ActiveRecord::Base
176
177
  # before_destroy 'self.class.delete_all "parent_id = #{id}"'
177
178
  # end
178
179
  #
179
- # Notice that single quotes (') are used so the <tt>#{id}</tt> part isn't evaluated until the callback is triggered. Also note that these
180
- # inline callbacks can be stacked just like the regular ones:
180
+ # Notice that single quotes (') are used so the <tt>#{id}</tt> part isn't evaluated until the callback
181
+ # is triggered. Also note that these inline callbacks can be stacked just like the regular ones:
181
182
  #
182
183
  # class Topic < ActiveRecord::Base
183
184
  # before_destroy 'self.class.delete_all "parent_id = #{id}"',
@@ -186,22 +187,24 @@ module ActiveRecord
186
187
  #
187
188
  # == The +after_find+ and +after_initialize+ exceptions
188
189
  #
189
- # Because +after_find+ and +after_initialize+ are called for each object found and instantiated by a finder, such as <tt>Base.find(:all)</tt>, we've had
190
- # to implement a simple performance constraint (50% more speed on a simple test case). Unlike all the other callbacks, +after_find+ and
191
- # +after_initialize+ will only be run if an explicit implementation is defined (<tt>def after_find</tt>). In that case, all of the
190
+ # Because +after_find+ and +after_initialize+ are called for each object found and instantiated by a finder,
191
+ # such as <tt>Base.find(:all)</tt>, we've had to implement a simple performance constraint (50% more speed
192
+ # on a simple test case). Unlike all the other callbacks, +after_find+ and +after_initialize+ will only be
193
+ # run if an explicit implementation is defined (<tt>def after_find</tt>). In that case, all of the
192
194
  # callback types will be called.
193
195
  #
194
196
  # == <tt>before_validation*</tt> returning statements
195
197
  #
196
- # If the returning value of a +before_validation+ callback can be evaluated to +false+, the process will be aborted and <tt>Base#save</tt> will return +false+.
197
- # If Base#save! is called it will raise a ActiveRecord::RecordInvalid exception.
198
- # Nothing will be appended to the errors object.
198
+ # If the returning value of a +before_validation+ callback can be evaluated to +false+, the process will be
199
+ # aborted and <tt>Base#save</tt> will return +false+. If Base#save! is called it will raise a
200
+ # ActiveRecord::RecordInvalid exception. Nothing will be appended to the errors object.
199
201
  #
200
202
  # == Canceling callbacks
201
203
  #
202
- # If a <tt>before_*</tt> callback returns +false+, all the later callbacks and the associated action are cancelled. If an <tt>after_*</tt> callback returns
203
- # +false+, all the later callbacks are cancelled. Callbacks are generally run in the order they are defined, with the exception of callbacks
204
- # defined as methods on the model, which are called last.
204
+ # If a <tt>before_*</tt> callback returns +false+, all the later callbacks and the associated action are
205
+ # cancelled. If an <tt>after_*</tt> callback returns +false+, all the later callbacks are cancelled.
206
+ # Callbacks are generally run in the order they are defined, with the exception of callbacks defined as
207
+ # methods on the model, which are called last.
205
208
  #
206
209
  # == Transactions
207
210
  #
@@ -217,7 +220,8 @@ module ActiveRecord
217
220
  #
218
221
  # == Debugging callbacks
219
222
  #
220
- # To list the methods and procs registered with a particular callback, append <tt>_callback_chain</tt> to the callback name that you wish to list and send that to your class from the Rails console:
223
+ # To list the methods and procs registered with a particular callback, append <tt>_callback_chain</tt> to
224
+ # the callback name that you wish to list and send that to your class from the Rails console:
221
225
  #
222
226
  # >> Topic.after_save_callback_chain
223
227
  # => [#<ActiveSupport::Callbacks::Callback:0x3f6a448
@@ -228,17 +232,17 @@ module ActiveRecord
228
232
  extend ActiveSupport::Concern
229
233
 
230
234
  CALLBACKS = [
231
- :after_initialize, :after_find, :before_validation, :after_validation,
235
+ :after_initialize, :after_find, :after_touch, :before_validation, :after_validation,
232
236
  :before_save, :around_save, :after_save, :before_create, :around_create,
233
237
  :after_create, :before_update, :around_update, :after_update,
234
- :before_destroy, :around_destroy, :after_destroy
238
+ :before_destroy, :around_destroy, :after_destroy, :after_commit, :after_rollback
235
239
  ]
236
240
 
237
241
  included do
238
242
  extend ActiveModel::Callbacks
239
243
  include ActiveModel::Validations::Callbacks
240
244
 
241
- define_model_callbacks :initialize, :find, :only => :after
245
+ define_model_callbacks :initialize, :find, :touch, :only => :after
242
246
  define_model_callbacks :save, :create, :update, :destroy
243
247
  end
244
248
 
@@ -256,6 +260,10 @@ module ActiveRecord
256
260
  _run_destroy_callbacks { super }
257
261
  end
258
262
 
263
+ def touch(*) #:nodoc:
264
+ _run_touch_callbacks { super }
265
+ end
266
+
259
267
  def deprecated_callback_method(symbol) #:nodoc:
260
268
  if respond_to?(symbol, true)
261
269
  ActiveSupport::Deprecation.warn("Overwriting #{symbol} in your models has been deprecated, please use Base##{symbol} :method_name instead")
@@ -93,29 +93,26 @@ module ActiveRecord
93
93
  # #connection can be called any number of times; the connection is
94
94
  # held in a hash keyed by the thread id.
95
95
  def connection
96
- if conn = @reserved_connections[current_connection_id]
97
- conn
98
- else
99
- @reserved_connections[current_connection_id] = checkout
100
- end
96
+ @reserved_connections[current_connection_id] ||= checkout
101
97
  end
102
98
 
103
99
  # Signal that the thread is finished with the current connection.
104
100
  # #release_connection releases the connection-thread association
105
101
  # and returns the connection to the pool.
106
- def release_connection
107
- conn = @reserved_connections.delete(current_connection_id)
102
+ def release_connection(with_id = current_connection_id)
103
+ conn = @reserved_connections.delete(with_id)
108
104
  checkin conn if conn
109
105
  end
110
106
 
111
107
  # If a connection already exists yield it to the block. If no connection
112
- # exists checkout a connection, yield it to the block, and checkin the
108
+ # exists checkout a connection, yield it to the block, and checkin the
113
109
  # connection when finished.
114
110
  def with_connection
115
- fresh_connection = true unless @reserved_connections[current_connection_id]
111
+ connection_id = current_connection_id
112
+ fresh_connection = true unless @reserved_connections[connection_id]
116
113
  yield connection
117
114
  ensure
118
- release_connection if fresh_connection
115
+ release_connection(connection_id) if fresh_connection
119
116
  end
120
117
 
121
118
  # Returns true if a connection has already been opened.
@@ -325,7 +322,7 @@ module ActiveRecord
325
322
  # already been opened.
326
323
  def connected?(klass)
327
324
  conn = retrieve_connection_pool(klass)
328
- conn ? conn.connected? : false
325
+ conn && conn.connected?
329
326
  end
330
327
 
331
328
  # Remove the connection for this class. This will close the active
@@ -42,7 +42,7 @@ module ActiveRecord
42
42
  65535
43
43
  end
44
44
 
45
- # the maximum length of a SQL query
45
+ # the maximum length of an SQL query
46
46
  def sql_query_length
47
47
  1048575
48
48
  end
@@ -57,14 +57,6 @@ module ActiveRecord
57
57
  end
58
58
  end
59
59
 
60
- def columns(*)
61
- if @query_cache_enabled
62
- @query_cache["SHOW FIELDS FROM #{args.first}"] ||= super
63
- else
64
- super
65
- end
66
- end
67
-
68
60
  private
69
61
  def cache_sql(sql)
70
62
  result =
@@ -30,7 +30,7 @@ module ActiveRecord
30
30
  if value.acts_like?(:date) || value.acts_like?(:time)
31
31
  "'#{quoted_date(value)}'"
32
32
  else
33
- "'#{quote_string(value.to_yaml)}'"
33
+ "'#{quote_string(value.to_s)}'"
34
34
  end
35
35
  end
36
36
  end
@@ -23,7 +23,8 @@ module ActiveRecord
23
23
  #
24
24
  # +name+ is the column's name, such as <tt>supplier_id</tt> in <tt>supplier_id int(11)</tt>.
25
25
  # +default+ is the type-casted default value, such as +new+ in <tt>sales_stage varchar(20) default 'new'</tt>.
26
- # +sql_type+ is used to extract the column's length, if necessary. For example +60+ in <tt>company_name varchar(60)</tt>.
26
+ # +sql_type+ is used to extract the column's length, if necessary. For example +60+ in
27
+ # <tt>company_name varchar(60)</tt>.
27
28
  # It will be mapped to one of the standard Rails SQL types in the <tt>type</tt> attribute.
28
29
  # +null+ determines if this column allows +NULL+ values.
29
30
  def initialize(name, default, sql_type = nil, null = true)
@@ -359,7 +360,8 @@ module ActiveRecord
359
360
  #
360
361
  # Available options are (none of these exists by default):
361
362
  # * <tt>:limit</tt> -
362
- # Requests a maximum column length. This is number of characters for <tt>:string</tt> and <tt>:text</tt> columns and number of bytes for :binary and :integer columns.
363
+ # Requests a maximum column length. This is number of characters for <tt>:string</tt> and
364
+ # <tt>:text</tt> columns and number of bytes for :binary and :integer columns.
363
365
  # * <tt>:default</tt> -
364
366
  # The column's default value. Use nil for NULL.
365
367
  # * <tt>:null</tt> -
@@ -462,8 +464,8 @@ module ActiveRecord
462
464
  # TableDefinition#timestamps that'll add created_at and +updated_at+ as datetimes.
463
465
  #
464
466
  # TableDefinition#references will add an appropriately-named _id column, plus a corresponding _type
465
- # column if the <tt>:polymorphic</tt> option is supplied. If <tt>:polymorphic</tt> is a hash of options, these will be
466
- # used when creating the <tt>_type</tt> column. So what can be written like this:
467
+ # column if the <tt>:polymorphic</tt> option is supplied. If <tt>:polymorphic</tt> is a hash of
468
+ # options, these will be used when creating the <tt>_type</tt> column. So what can be written like this:
467
469
  #
468
470
  # create_table :taggings do |t|
469
471
  # t.integer :tag_id, :tagger_id, :taggable_id
@@ -526,7 +528,7 @@ module ActiveRecord
526
528
  # concatenated together. This string can then be prepended and appended to
527
529
  # to generate the final SQL to create the table.
528
530
  def to_sql
529
- @columns.map(&:to_sql) * ', '
531
+ @columns.map { |c| c.to_sql } * ', '
530
532
  end
531
533
 
532
534
  private
@@ -535,7 +537,7 @@ module ActiveRecord
535
537
  end
536
538
  end
537
539
 
538
- # Represents a SQL table in an abstract way for updating a table.
540
+ # Represents an SQL table in an abstract way for updating a table.
539
541
  # Also see TableDefinition and SchemaStatements#create_table
540
542
  #
541
543
  # Available transformations are:
@@ -110,8 +110,8 @@ module ActiveRecord
110
110
  #
111
111
  # Also note that this just sets the primary key in the table. You additionally
112
112
  # need to configure the primary key in the model via the +set_primary_key+ macro.
113
- # Models do NOT auto-detect the primary key from their table definition.
114
- #
113
+ # Models do NOT auto-detect the primary key from their table definition.
114
+ #
115
115
  # [<tt>:options</tt>]
116
116
  # Any extra options you want appended to the table definition.
117
117
  # [<tt>:temporary</tt>]
@@ -327,6 +327,8 @@ module ActiveRecord
327
327
  #
328
328
  # Note: SQLite doesn't support index length
329
329
  def add_index(table_name, column_name, options = {})
330
+ options[:name] = options[:name].to_s if options.key?(:name)
331
+
330
332
  column_names = Array.wrap(column_name)
331
333
  index_name = index_name(table_name, :column => column_names)
332
334
 
@@ -448,7 +450,7 @@ module ActiveRecord
448
450
  version = version.to_i
449
451
  sm_table = quote_table_name(ActiveRecord::Migrator.schema_migrations_table_name)
450
452
 
451
- migrated = select_values("SELECT version FROM #{sm_table}").map(&:to_i)
453
+ migrated = select_values("SELECT version FROM #{sm_table}").map { |v| v.to_i }
452
454
  versions = Dir["#{migrations_path}/[0-9]*_*.rb"].map do |filename|
453
455
  filename.split('/').last.split('_').first.to_i
454
456
  end
@@ -31,6 +31,7 @@ module ActiveRecord
31
31
  mysql.ssl_set(config[:sslkey], config[:sslcert], config[:sslca], config[:sslcapath], config[:sslcipher]) if config[:sslca] || config[:sslkey]
32
32
 
33
33
  default_flags = Mysql.const_defined?(:CLIENT_MULTI_RESULTS) ? Mysql::CLIENT_MULTI_RESULTS : 0
34
+ default_flags |= Mysql::CLIENT_FOUND_ROWS if Mysql.const_defined?(:CLIENT_FOUND_ROWS)
34
35
  options = [host, username, password, database, port, socket, default_flags]
35
36
  ConnectionAdapters::MysqlAdapter.new(mysql, logger, options, config)
36
37
  end
@@ -275,10 +276,12 @@ module ActiveRecord
275
276
  rows = []
276
277
  result.each { |row| rows << row }
277
278
  result.free
279
+ @connection.more_results && @connection.next_result # invoking stored procedures with CLIENT_MULTI_RESULTS requires this to tidy up else connection will be dropped
278
280
  rows
279
281
  end
280
282
 
281
- # Executes a SQL query and returns a MySQL::Result object. Note that you have to free the Result object after you're done using it.
283
+ # Executes an SQL query and returns a MySQL::Result object. Note that you have to free
284
+ # the Result object after you're done using it.
282
285
  def execute(sql, name = nil) #:nodoc:
283
286
  if name == :skip_logging
284
287
  @connection.query(sql)
@@ -617,6 +620,7 @@ module ActiveRecord
617
620
  rows = []
618
621
  result.each_hash { |row| rows << row }
619
622
  result.free
623
+ @connection.more_results && @connection.next_result # invoking stored procedures with CLIENT_MULTI_RESULTS requires this to tidy up else connection will be dropped
620
624
  rows
621
625
  end
622
626
 
@@ -183,10 +183,14 @@ module ActiveRecord
183
183
  # * <tt>:username</tt> - Defaults to nothing.
184
184
  # * <tt>:password</tt> - Defaults to nothing.
185
185
  # * <tt>:database</tt> - The name of the database. No default, must be provided.
186
- # * <tt>:schema_search_path</tt> - An optional schema search path for the connection given as a string of comma-separated schema names. This is backward-compatible with the <tt>:schema_order</tt> option.
187
- # * <tt>:encoding</tt> - An optional client encoding that is used in a <tt>SET client_encoding TO <encoding></tt> call on the connection.
188
- # * <tt>:min_messages</tt> - An optional client min messages that is used in a <tt>SET client_min_messages TO <min_messages></tt> call on the connection.
189
- # * <tt>:allow_concurrency</tt> - If true, use async query methods so Ruby threads don't deadlock; otherwise, use blocking query methods.
186
+ # * <tt>:schema_search_path</tt> - An optional schema search path for the connection given
187
+ # as a string of comma-separated schema names. This is backward-compatible with the <tt>:schema_order</tt> option.
188
+ # * <tt>:encoding</tt> - An optional client encoding that is used in a <tt>SET client_encoding TO
189
+ # <encoding></tt> call on the connection.
190
+ # * <tt>:min_messages</tt> - An optional client min messages that is used in a
191
+ # <tt>SET client_min_messages TO <min_messages></tt> call on the connection.
192
+ # * <tt>:allow_concurrency</tt> - If true, use async query methods so Ruby threads don't deadlock;
193
+ # otherwise, use blocking query methods.
190
194
  class PostgreSQLAdapter < AbstractAdapter
191
195
  ADAPTER_NAME = 'PostgreSQL'.freeze
192
196
 
@@ -875,7 +879,7 @@ module ActiveRecord
875
879
  # Construct a clean list of column names from the ORDER BY clause, removing
876
880
  # any ASC/DESC modifiers
877
881
  order_columns = order_by.split(',').collect { |s| s.split.first }
878
- order_columns.delete_if(&:blank?)
882
+ order_columns.delete_if { |c| c.blank? }
879
883
  order_columns = order_columns.zip((0...order_columns.size).to_a).map { |s,i| "#{s} AS alias_#{i}" }
880
884
 
881
885
  # Return a DISTINCT ON() clause that's distinct on the columns we want but includes
@@ -29,8 +29,8 @@ module ActiveRecord
29
29
  end
30
30
  end
31
31
 
32
- # The SQLite adapter works with both the 2.x and 3.x series of SQLite with the sqlite-ruby drivers (available both as gems and
33
- # from http://rubyforge.org/projects/sqlite-ruby/).
32
+ # The SQLite adapter works with both the 2.x and 3.x series of SQLite with the sqlite-ruby
33
+ # drivers (available both as gems and from http://rubyforge.org/projects/sqlite-ruby/).
34
34
  #
35
35
  # Options:
36
36
  #
@@ -40,11 +40,11 @@ module ActiveRecord
40
40
  include Comparable
41
41
 
42
42
  def initialize(version_string)
43
- @version = version_string.split('.').map(&:to_i)
43
+ @version = version_string.split('.').map { |v| v.to_i }
44
44
  end
45
45
 
46
46
  def <=>(version_string)
47
- @version <=> version_string.split('.').map(&:to_i)
47
+ @version <=> version_string.split('.').map { |v| v.to_i }
48
48
  end
49
49
  end
50
50
 
@@ -345,7 +345,7 @@ module ActiveRecord
345
345
  name = name[5..-1]
346
346
  end
347
347
 
348
- to_column_names = columns(to).map(&:name)
348
+ to_column_names = columns(to).map { |c| c.name }
349
349
  columns = index.columns.map {|c| rename[c] || c }.select do |column|
350
350
  to_column_names.include?(column)
351
351
  end
@@ -1,9 +1,9 @@
1
1
  module ActiveRecord
2
2
 
3
3
  # = Active Record Dynamic Finder Match
4
- #
5
- # Provides dynamic attribute-based finders such as <tt>find_by_country</tt>
6
- # if, for example, the <tt>Person</tt> has an attribute with that name.
4
+ #
5
+ # Refer to ActiveRecord::Base documentation for Dynamic attribute-based finders for detailed info
6
+ #
7
7
  class DynamicFinderMatch
8
8
  def self.match(method)
9
9
  df_match = self.new(method)
@@ -1,7 +1,7 @@
1
1
  module ActiveRecord
2
2
 
3
3
  # = Active Record Dynamic Scope Match
4
- #
4
+ #
5
5
  # Provides dynamic attribute-based scopes such as <tt>scoped_by_price(4.99)</tt>
6
6
  # if, for example, the <tt>Product</tt> has an attribute with that name. You can
7
7
  # chain more <tt>scoped_by_* </tt> methods after the other. It acts like a named
@@ -30,7 +30,8 @@ module ActiveRecord
30
30
  class SerializationTypeMismatch < ActiveRecordError
31
31
  end
32
32
 
33
- # Raised when adapter not specified on connection (or configuration file <tt>config/database.yml</tt> misses adapter field).
33
+ # Raised when adapter not specified on connection (or configuration file <tt>config/database.yml</tt>
34
+ # misses adapter field).
34
35
  class AdapterNotSpecified < ActiveRecordError
35
36
  end
36
37
 
@@ -38,7 +39,8 @@ module ActiveRecord
38
39
  class AdapterNotFound < ActiveRecordError
39
40
  end
40
41
 
41
- # Raised when connection to the database could not been established (for example when <tt>connection=</tt> is given a nil object).
42
+ # Raised when connection to the database could not been established (for example when <tt>connection=</tt>
43
+ # is given a nil object).
42
44
  class ConnectionNotEstablished < ActiveRecordError
43
45
  end
44
46
 
@@ -51,7 +53,8 @@ module ActiveRecord
51
53
  class RecordNotSaved < ActiveRecordError
52
54
  end
53
55
 
54
- # Raised when SQL statement cannot be executed by the database (for example, it's often the case for MySQL when Ruby driver used is too old).
56
+ # Raised when SQL statement cannot be executed by the database (for example, it's often the case for
57
+ # MySQL when Ruby driver used is too old).
55
58
  class StatementInvalid < ActiveRecordError
56
59
  end
57
60
 
@@ -78,7 +81,8 @@ module ActiveRecord
78
81
  class InvalidForeignKey < WrappedDatabaseException
79
82
  end
80
83
 
81
- # Raised when number of bind variables in statement given to <tt>:condition</tt> key (for example, when using +find+ method)
84
+ # Raised when number of bind variables in statement given to <tt>:condition</tt> key (for example,
85
+ # when using +find+ method)
82
86
  # does not match number of expected variables.
83
87
  #
84
88
  # For example, in
@@ -165,4 +169,4 @@ module ActiveRecord
165
169
  @errors = errors
166
170
  end
167
171
  end
168
- end
172
+ end