activerecord 4.0.13 → 4.1.0.beta1
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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +745 -2700
- data/README.rdoc +2 -2
- data/examples/performance.rb +30 -18
- data/examples/simple.rb +4 -4
- data/lib/active_record.rb +2 -6
- data/lib/active_record/aggregations.rb +2 -1
- data/lib/active_record/association_relation.rb +0 -4
- data/lib/active_record/associations.rb +87 -43
- data/lib/active_record/associations/alias_tracker.rb +1 -3
- data/lib/active_record/associations/association.rb +8 -16
- data/lib/active_record/associations/association_scope.rb +5 -16
- data/lib/active_record/associations/belongs_to_association.rb +34 -25
- data/lib/active_record/associations/belongs_to_polymorphic_association.rb +1 -1
- data/lib/active_record/associations/builder/association.rb +78 -54
- data/lib/active_record/associations/builder/belongs_to.rb +91 -58
- data/lib/active_record/associations/builder/collection_association.rb +47 -45
- data/lib/active_record/associations/builder/has_and_belongs_to_many.rb +107 -25
- data/lib/active_record/associations/builder/has_many.rb +2 -2
- data/lib/active_record/associations/builder/has_one.rb +5 -7
- data/lib/active_record/associations/builder/singular_association.rb +6 -7
- data/lib/active_record/associations/collection_association.rb +68 -105
- data/lib/active_record/associations/collection_proxy.rb +12 -15
- data/lib/active_record/associations/has_many_association.rb +11 -9
- data/lib/active_record/associations/has_many_through_association.rb +16 -12
- data/lib/active_record/associations/has_one_association.rb +1 -1
- data/lib/active_record/associations/join_dependency.rb +204 -165
- data/lib/active_record/associations/join_dependency/join_association.rb +43 -101
- data/lib/active_record/associations/join_dependency/join_base.rb +6 -8
- data/lib/active_record/associations/join_dependency/join_part.rb +18 -37
- data/lib/active_record/associations/join_helper.rb +2 -11
- data/lib/active_record/associations/preloader.rb +89 -34
- data/lib/active_record/associations/preloader/association.rb +43 -25
- data/lib/active_record/associations/preloader/collection_association.rb +2 -2
- data/lib/active_record/associations/preloader/has_many_through.rb +1 -1
- data/lib/active_record/associations/preloader/singular_association.rb +3 -3
- data/lib/active_record/associations/preloader/through_association.rb +58 -26
- data/lib/active_record/associations/singular_association.rb +6 -5
- data/lib/active_record/associations/through_association.rb +2 -2
- data/lib/active_record/attribute_assignment.rb +5 -2
- data/lib/active_record/attribute_methods.rb +45 -40
- data/lib/active_record/attribute_methods/before_type_cast.rb +2 -1
- data/lib/active_record/attribute_methods/dirty.rb +8 -22
- data/lib/active_record/attribute_methods/primary_key.rb +1 -7
- data/lib/active_record/attribute_methods/read.rb +55 -28
- data/lib/active_record/attribute_methods/serialization.rb +12 -33
- data/lib/active_record/attribute_methods/time_zone_conversion.rb +1 -13
- data/lib/active_record/attribute_methods/write.rb +37 -12
- data/lib/active_record/autosave_association.rb +207 -207
- data/lib/active_record/base.rb +5 -1
- data/lib/active_record/callbacks.rb +2 -2
- data/lib/active_record/connection_adapters/abstract/connection_pool.rb +2 -7
- data/lib/active_record/connection_adapters/abstract/database_statements.rb +11 -22
- data/lib/active_record/connection_adapters/abstract/query_cache.rb +12 -14
- data/lib/active_record/connection_adapters/abstract/quoting.rb +1 -5
- data/lib/active_record/connection_adapters/abstract/savepoints.rb +21 -0
- data/lib/active_record/connection_adapters/abstract/schema_creation.rb +84 -0
- data/lib/active_record/connection_adapters/abstract/schema_definitions.rb +9 -8
- data/lib/active_record/connection_adapters/abstract/schema_statements.rb +52 -83
- data/lib/active_record/connection_adapters/abstract/transaction.rb +0 -5
- data/lib/active_record/connection_adapters/abstract_adapter.rb +14 -97
- data/lib/active_record/connection_adapters/abstract_mysql_adapter.rb +58 -60
- data/lib/active_record/connection_adapters/column.rb +1 -35
- data/lib/active_record/connection_adapters/connection_specification.rb +2 -2
- data/lib/active_record/connection_adapters/mysql2_adapter.rb +3 -4
- data/lib/active_record/connection_adapters/mysql_adapter.rb +16 -15
- data/lib/active_record/connection_adapters/postgresql/array_parser.rb +24 -18
- data/lib/active_record/connection_adapters/postgresql/cast.rb +20 -16
- data/lib/active_record/connection_adapters/postgresql/database_statements.rb +23 -43
- data/lib/active_record/connection_adapters/postgresql/oid.rb +19 -12
- data/lib/active_record/connection_adapters/postgresql/quoting.rb +28 -23
- data/lib/active_record/connection_adapters/postgresql/schema_statements.rb +8 -30
- data/lib/active_record/connection_adapters/postgresql_adapter.rb +92 -75
- data/lib/active_record/connection_adapters/schema_cache.rb +8 -29
- data/lib/active_record/connection_adapters/sqlite3_adapter.rb +31 -64
- data/lib/active_record/connection_handling.rb +2 -2
- data/lib/active_record/core.rb +22 -43
- data/lib/active_record/counter_cache.rb +7 -7
- data/lib/active_record/enum.rb +100 -0
- data/lib/active_record/errors.rb +10 -5
- data/lib/active_record/fixture_set/file.rb +2 -1
- data/lib/active_record/fixtures.rb +171 -74
- data/lib/active_record/inheritance.rb +16 -22
- data/lib/active_record/integration.rb +52 -1
- data/lib/active_record/locking/optimistic.rb +7 -2
- data/lib/active_record/locking/pessimistic.rb +1 -1
- data/lib/active_record/log_subscriber.rb +5 -12
- data/lib/active_record/migration.rb +62 -46
- data/lib/active_record/migration/command_recorder.rb +7 -13
- data/lib/active_record/model_schema.rb +7 -14
- data/lib/active_record/nested_attributes.rb +10 -8
- data/lib/active_record/no_touching.rb +52 -0
- data/lib/active_record/null_relation.rb +3 -3
- data/lib/active_record/persistence.rb +16 -34
- data/lib/active_record/querying.rb +14 -12
- data/lib/active_record/railtie.rb +0 -50
- data/lib/active_record/railties/databases.rake +12 -15
- data/lib/active_record/readonly_attributes.rb +0 -6
- data/lib/active_record/reflection.rb +189 -75
- data/lib/active_record/relation.rb +69 -94
- data/lib/active_record/relation/batches.rb +57 -23
- data/lib/active_record/relation/calculations.rb +36 -43
- data/lib/active_record/relation/delegation.rb +54 -39
- data/lib/active_record/relation/finder_methods.rb +107 -62
- data/lib/active_record/relation/merger.rb +7 -20
- data/lib/active_record/relation/predicate_builder.rb +57 -38
- data/lib/active_record/relation/predicate_builder/array_handler.rb +29 -0
- data/lib/active_record/relation/predicate_builder/relation_handler.rb +13 -0
- data/lib/active_record/relation/query_methods.rb +110 -98
- data/lib/active_record/relation/spawn_methods.rb +1 -2
- data/lib/active_record/result.rb +45 -6
- data/lib/active_record/runtime_registry.rb +5 -0
- data/lib/active_record/sanitization.rb +6 -8
- data/lib/active_record/schema_dumper.rb +16 -5
- data/lib/active_record/schema_migration.rb +24 -25
- data/lib/active_record/scoping/default.rb +5 -18
- data/lib/active_record/scoping/named.rb +8 -29
- data/lib/active_record/store.rb +56 -28
- data/lib/active_record/tasks/database_tasks.rb +8 -4
- data/lib/active_record/timestamp.rb +4 -4
- data/lib/active_record/transactions.rb +8 -10
- data/lib/active_record/validations/presence.rb +1 -1
- data/lib/active_record/validations/uniqueness.rb +1 -6
- data/lib/active_record/version.rb +1 -1
- data/lib/rails/generators/active_record.rb +2 -8
- data/lib/rails/generators/active_record/migration.rb +18 -0
- data/lib/rails/generators/active_record/migration/migration_generator.rb +4 -0
- data/lib/rails/generators/active_record/model/model_generator.rb +4 -0
- metadata +32 -45
- data/lib/active_record/associations/has_and_belongs_to_many_association.rb +0 -65
- data/lib/active_record/associations/preloader/has_and_belongs_to_many.rb +0 -60
- data/lib/active_record/tasks/firebird_database_tasks.rb +0 -56
- data/lib/active_record/tasks/oracle_database_tasks.rb +0 -45
- data/lib/active_record/tasks/sqlserver_database_tasks.rb +0 -48
- data/lib/active_record/test_case.rb +0 -102
@@ -1,4 +1,3 @@
|
|
1
|
-
require 'active_support/deprecation/reporting'
|
2
1
|
|
3
2
|
module ActiveRecord
|
4
3
|
module ConnectionAdapters
|
@@ -16,13 +15,8 @@ module ActiveRecord
|
|
16
15
|
prepare_default_proc
|
17
16
|
end
|
18
17
|
|
19
|
-
def primary_keys(table_name
|
20
|
-
|
21
|
-
@primary_keys[table_name]
|
22
|
-
else
|
23
|
-
ActiveSupport::Deprecation.warn('call primary_keys with a table name!')
|
24
|
-
@primary_keys.dup
|
25
|
-
end
|
18
|
+
def primary_keys(table_name)
|
19
|
+
@primary_keys[table_name]
|
26
20
|
end
|
27
21
|
|
28
22
|
# A cached lookup for table existence.
|
@@ -41,34 +35,19 @@ module ActiveRecord
|
|
41
35
|
end
|
42
36
|
end
|
43
37
|
|
44
|
-
def tables(name
|
45
|
-
|
46
|
-
@tables[name]
|
47
|
-
else
|
48
|
-
ActiveSupport::Deprecation.warn('call tables with a name!')
|
49
|
-
@tables.dup
|
50
|
-
end
|
38
|
+
def tables(name)
|
39
|
+
@tables[name]
|
51
40
|
end
|
52
41
|
|
53
42
|
# Get the columns for a table
|
54
|
-
def columns(table
|
55
|
-
|
56
|
-
@columns[table]
|
57
|
-
else
|
58
|
-
ActiveSupport::Deprecation.warn('call columns with a table name!')
|
59
|
-
@columns.dup
|
60
|
-
end
|
43
|
+
def columns(table)
|
44
|
+
@columns[table]
|
61
45
|
end
|
62
46
|
|
63
47
|
# Get the columns for a table as a hash, key is the column name
|
64
48
|
# value is the column object.
|
65
|
-
def columns_hash(table
|
66
|
-
|
67
|
-
@columns_hash[table]
|
68
|
-
else
|
69
|
-
ActiveSupport::Deprecation.warn('call columns_hash with a table name!')
|
70
|
-
@columns_hash.dup
|
71
|
-
end
|
49
|
+
def columns_hash(table)
|
50
|
+
@columns_hash[table]
|
72
51
|
end
|
73
52
|
|
74
53
|
# Clears out internal caches
|
@@ -53,6 +53,23 @@ module ActiveRecord
|
|
53
53
|
#
|
54
54
|
# * <tt>:database</tt> - Path to the database file.
|
55
55
|
class SQLite3Adapter < AbstractAdapter
|
56
|
+
include Savepoints
|
57
|
+
|
58
|
+
NATIVE_DATABASE_TYPES = {
|
59
|
+
primary_key: 'INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL',
|
60
|
+
string: { name: "varchar", limit: 255 },
|
61
|
+
text: { name: "text" },
|
62
|
+
integer: { name: "integer" },
|
63
|
+
float: { name: "float" },
|
64
|
+
decimal: { name: "decimal" },
|
65
|
+
datetime: { name: "datetime" },
|
66
|
+
timestamp: { name: "datetime" },
|
67
|
+
time: { name: "time" },
|
68
|
+
date: { name: "date" },
|
69
|
+
binary: { name: "blob" },
|
70
|
+
boolean: { name: "boolean" }
|
71
|
+
}
|
72
|
+
|
56
73
|
class Version
|
57
74
|
include Comparable
|
58
75
|
|
@@ -124,14 +141,12 @@ module ActiveRecord
|
|
124
141
|
'SQLite'
|
125
142
|
end
|
126
143
|
|
127
|
-
# Returns true
|
128
144
|
def supports_ddl_transactions?
|
129
145
|
true
|
130
146
|
end
|
131
147
|
|
132
|
-
# Returns true if SQLite version is '3.6.8' or greater, false otherwise.
|
133
148
|
def supports_savepoints?
|
134
|
-
|
149
|
+
true
|
135
150
|
end
|
136
151
|
|
137
152
|
# Returns true, since this connection adapter supports prepared statement
|
@@ -145,7 +160,6 @@ module ActiveRecord
|
|
145
160
|
true
|
146
161
|
end
|
147
162
|
|
148
|
-
# Returns true.
|
149
163
|
def supports_primary_key? #:nodoc:
|
150
164
|
true
|
151
165
|
end
|
@@ -154,7 +168,6 @@ module ActiveRecord
|
|
154
168
|
true
|
155
169
|
end
|
156
170
|
|
157
|
-
# Returns true
|
158
171
|
def supports_add_column?
|
159
172
|
true
|
160
173
|
end
|
@@ -176,16 +189,6 @@ module ActiveRecord
|
|
176
189
|
@statements.clear
|
177
190
|
end
|
178
191
|
|
179
|
-
# Returns true
|
180
|
-
def supports_count_distinct? #:nodoc:
|
181
|
-
true
|
182
|
-
end
|
183
|
-
|
184
|
-
# Returns true
|
185
|
-
def supports_autoincrement? #:nodoc:
|
186
|
-
true
|
187
|
-
end
|
188
|
-
|
189
192
|
def supports_index_sort_order?
|
190
193
|
true
|
191
194
|
end
|
@@ -198,20 +201,7 @@ module ActiveRecord
|
|
198
201
|
end
|
199
202
|
|
200
203
|
def native_database_types #:nodoc:
|
201
|
-
|
202
|
-
:primary_key => default_primary_key_type,
|
203
|
-
:string => { :name => "varchar", :limit => 255 },
|
204
|
-
:text => { :name => "text" },
|
205
|
-
:integer => { :name => "integer" },
|
206
|
-
:float => { :name => "float" },
|
207
|
-
:decimal => { :name => "decimal" },
|
208
|
-
:datetime => { :name => "datetime" },
|
209
|
-
:timestamp => { :name => "datetime" },
|
210
|
-
:time => { :name => "time" },
|
211
|
-
:date => { :name => "date" },
|
212
|
-
:binary => { :name => "blob" },
|
213
|
-
:boolean => { :name => "boolean" }
|
214
|
-
}
|
204
|
+
NATIVE_DATABASE_TYPES
|
215
205
|
end
|
216
206
|
|
217
207
|
# Returns the current database encoding format as a string, eg: 'UTF-8'
|
@@ -219,7 +209,6 @@ module ActiveRecord
|
|
219
209
|
@connection.encoding.to_s
|
220
210
|
end
|
221
211
|
|
222
|
-
# Returns true.
|
223
212
|
def supports_explain?
|
224
213
|
true
|
225
214
|
end
|
@@ -227,8 +216,8 @@ module ActiveRecord
|
|
227
216
|
# QUOTING ==================================================
|
228
217
|
|
229
218
|
def quote(value, column = nil)
|
230
|
-
if value.kind_of?(String) && column && column.type == :binary
|
231
|
-
s =
|
219
|
+
if value.kind_of?(String) && column && column.type == :binary
|
220
|
+
s = value.unpack("H*")[0]
|
232
221
|
"x'#{s}'"
|
233
222
|
else
|
234
223
|
super
|
@@ -292,17 +281,17 @@ module ActiveRecord
|
|
292
281
|
end
|
293
282
|
|
294
283
|
def exec_query(sql, name = nil, binds = [])
|
295
|
-
|
284
|
+
type_casted_binds = binds.map { |col, val|
|
285
|
+
[col, type_cast(val, col)]
|
286
|
+
}
|
296
287
|
|
288
|
+
log(sql, name, type_casted_binds) do
|
297
289
|
# Don't cache statements if they are not prepared
|
298
290
|
if without_prepared_statement?(binds)
|
299
291
|
stmt = @connection.prepare(sql)
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
ensure
|
304
|
-
stmt.close
|
305
|
-
end
|
292
|
+
cols = stmt.columns
|
293
|
+
records = stmt.to_a
|
294
|
+
stmt.close
|
306
295
|
stmt = records
|
307
296
|
else
|
308
297
|
cache = @statements[sql] ||= {
|
@@ -311,9 +300,7 @@ module ActiveRecord
|
|
311
300
|
stmt = cache[:stmt]
|
312
301
|
cols = cache[:cols] ||= stmt.columns
|
313
302
|
stmt.reset!
|
314
|
-
stmt.bind_params
|
315
|
-
type_cast(val, col)
|
316
|
-
}
|
303
|
+
stmt.bind_params type_casted_binds.map { |_, val| val }
|
317
304
|
end
|
318
305
|
|
319
306
|
ActiveRecord::Result.new(cols, stmt.to_a)
|
@@ -350,20 +337,8 @@ module ActiveRecord
|
|
350
337
|
end
|
351
338
|
alias :create :insert_sql
|
352
339
|
|
353
|
-
def select_rows(sql, name = nil
|
354
|
-
exec_query(sql, name
|
355
|
-
end
|
356
|
-
|
357
|
-
def create_savepoint
|
358
|
-
execute("SAVEPOINT #{current_savepoint_name}")
|
359
|
-
end
|
360
|
-
|
361
|
-
def rollback_to_savepoint
|
362
|
-
execute("ROLLBACK TO SAVEPOINT #{current_savepoint_name}")
|
363
|
-
end
|
364
|
-
|
365
|
-
def release_savepoint
|
366
|
-
execute("RELEASE SAVEPOINT #{current_savepoint_name}")
|
340
|
+
def select_rows(sql, name = nil)
|
341
|
+
exec_query(sql, name).rows
|
367
342
|
end
|
368
343
|
|
369
344
|
def begin_db_transaction #:nodoc:
|
@@ -609,14 +584,6 @@ module ActiveRecord
|
|
609
584
|
@sqlite_version ||= SQLite3Adapter::Version.new(select_value('select sqlite_version(*)'))
|
610
585
|
end
|
611
586
|
|
612
|
-
def default_primary_key_type
|
613
|
-
if supports_autoincrement?
|
614
|
-
'INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL'
|
615
|
-
else
|
616
|
-
'INTEGER PRIMARY KEY NOT NULL'
|
617
|
-
end
|
618
|
-
end
|
619
|
-
|
620
587
|
def translate_exception(exception, message)
|
621
588
|
case exception.message
|
622
589
|
# SQLite 3.8.2 returns a newly formatted error message:
|
@@ -15,14 +15,14 @@ module ActiveRecord
|
|
15
15
|
# Example for SQLite database:
|
16
16
|
#
|
17
17
|
# ActiveRecord::Base.establish_connection(
|
18
|
-
# adapter: "
|
18
|
+
# adapter: "sqlite",
|
19
19
|
# database: "path/to/dbfile"
|
20
20
|
# )
|
21
21
|
#
|
22
22
|
# Also accepts keys as strings (for parsing from YAML for example):
|
23
23
|
#
|
24
24
|
# ActiveRecord::Base.establish_connection(
|
25
|
-
# "adapter" => "
|
25
|
+
# "adapter" => "sqlite",
|
26
26
|
# "database" => "path/to/dbfile"
|
27
27
|
# )
|
28
28
|
#
|
data/lib/active_record/core.rb
CHANGED
@@ -69,13 +69,10 @@ module ActiveRecord
|
|
69
69
|
mattr_accessor :timestamped_migrations, instance_writer: false
|
70
70
|
self.timestamped_migrations = true
|
71
71
|
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
# you can disable the feature entirely. This will be the default with Rails 4.1.
|
77
|
-
mattr_accessor :disable_implicit_join_references, instance_writer: false
|
78
|
-
self.disable_implicit_join_references = false
|
72
|
+
def self.disable_implicit_join_references=(value)
|
73
|
+
ActiveSupport::Deprecation.warn("Implicit join references were removed with Rails 4.1." \
|
74
|
+
"Make sure to remove this configuration because it does nothing.")
|
75
|
+
end
|
79
76
|
|
80
77
|
class_attribute :default_connection_handler, instance_writer: false
|
81
78
|
|
@@ -94,12 +91,12 @@ module ActiveRecord
|
|
94
91
|
def initialize_generated_modules
|
95
92
|
super
|
96
93
|
|
97
|
-
|
94
|
+
generated_association_methods
|
98
95
|
end
|
99
96
|
|
100
|
-
def
|
101
|
-
@
|
102
|
-
mod = const_set(:
|
97
|
+
def generated_association_methods
|
98
|
+
@generated_association_methods ||= begin
|
99
|
+
mod = const_set(:GeneratedAssociationMethods, Module.new)
|
103
100
|
include mod
|
104
101
|
mod
|
105
102
|
end
|
@@ -137,19 +134,18 @@ module ActiveRecord
|
|
137
134
|
|
138
135
|
# Returns the Arel engine.
|
139
136
|
def arel_engine
|
140
|
-
@arel_engine ||=
|
137
|
+
@arel_engine ||=
|
141
138
|
if Base == self || connection_handler.retrieve_connection_pool(self)
|
142
139
|
self
|
143
140
|
else
|
144
141
|
superclass.arel_engine
|
145
142
|
end
|
146
|
-
end
|
147
143
|
end
|
148
144
|
|
149
145
|
private
|
150
146
|
|
151
147
|
def relation #:nodoc:
|
152
|
-
relation = Relation.
|
148
|
+
relation = Relation.create(self, arel_table)
|
153
149
|
|
154
150
|
if finder_needs_type_condition?
|
155
151
|
relation.where(type_condition).create_with(inheritance_column.to_sym => sti_name)
|
@@ -257,7 +253,6 @@ module ActiveRecord
|
|
257
253
|
@attributes_cache = {}
|
258
254
|
|
259
255
|
@new_record = true
|
260
|
-
@destroyed = false
|
261
256
|
|
262
257
|
ensure_proper_type
|
263
258
|
super
|
@@ -276,7 +271,7 @@ module ActiveRecord
|
|
276
271
|
# Post.new.encode_with(coder)
|
277
272
|
# coder # => {"attributes" => {"id" => nil, ... }}
|
278
273
|
def encode_with(coder)
|
279
|
-
coder['attributes'] =
|
274
|
+
coder['attributes'] = attributes
|
280
275
|
end
|
281
276
|
|
282
277
|
# Returns true if +comparison_object+ is the same exact object, or +comparison_object+
|
@@ -291,7 +286,7 @@ module ActiveRecord
|
|
291
286
|
def ==(comparison_object)
|
292
287
|
super ||
|
293
288
|
comparison_object.instance_of?(self.class) &&
|
294
|
-
id
|
289
|
+
id &&
|
295
290
|
comparison_object.id == id
|
296
291
|
end
|
297
292
|
alias :eql? :==
|
@@ -319,6 +314,8 @@ module ActiveRecord
|
|
319
314
|
def <=>(other_object)
|
320
315
|
if other_object.is_a?(self.class)
|
321
316
|
self.to_key <=> other_object.to_key
|
317
|
+
else
|
318
|
+
super
|
322
319
|
end
|
323
320
|
end
|
324
321
|
|
@@ -333,14 +330,6 @@ module ActiveRecord
|
|
333
330
|
@readonly = true
|
334
331
|
end
|
335
332
|
|
336
|
-
# Returns the connection currently associated with the class. This can
|
337
|
-
# also be used to "borrow" the connection to do database work that isn't
|
338
|
-
# easily done without going straight to SQL.
|
339
|
-
def connection
|
340
|
-
ActiveSupport::Deprecation.warn("#connection is deprecated in favour of accessing it via the class")
|
341
|
-
self.class.connection
|
342
|
-
end
|
343
|
-
|
344
333
|
def connection_handler
|
345
334
|
self.class.connection_handler
|
346
335
|
end
|
@@ -363,7 +352,7 @@ module ActiveRecord
|
|
363
352
|
|
364
353
|
# Returns a hash of the given methods with their names as keys and returned values as values.
|
365
354
|
def slice(*methods)
|
366
|
-
Hash[methods.map { |method| [method, public_send(method)] }].with_indifferent_access
|
355
|
+
Hash[methods.map! { |method| [method, public_send(method)] }].with_indifferent_access
|
367
356
|
end
|
368
357
|
|
369
358
|
def set_transaction_state(state) # :nodoc:
|
@@ -374,17 +363,6 @@ module ActiveRecord
|
|
374
363
|
!_rollback_callbacks.empty? || !_commit_callbacks.empty? || !_create_callbacks.empty?
|
375
364
|
end
|
376
365
|
|
377
|
-
# Required to deserialize Syck properly.
|
378
|
-
if YAML.const_defined?(:ENGINE) && YAML::ENGINE.syck?
|
379
|
-
ActiveSupport::Deprecation.warn(
|
380
|
-
"Syck is deprecated and support for serialization has been removed." \
|
381
|
-
" ActiveRecord::Core#yaml_initialize will be removed in 4.1 which will break deserialization support with Syck."
|
382
|
-
)
|
383
|
-
def yaml_initialize(tag, coder) # :nodoc:
|
384
|
-
init_with(coder)
|
385
|
-
end
|
386
|
-
end
|
387
|
-
|
388
366
|
private
|
389
367
|
|
390
368
|
# Updates the attributes on this particular ActiveRecord object so that
|
@@ -409,10 +387,13 @@ module ActiveRecord
|
|
409
387
|
end
|
410
388
|
|
411
389
|
def update_attributes_from_transaction_state(transaction_state, depth)
|
412
|
-
if transaction_state &&
|
390
|
+
if transaction_state && !has_transactional_callbacks?
|
413
391
|
unless @reflects_state[depth]
|
414
|
-
|
415
|
-
|
392
|
+
if transaction_state.committed?
|
393
|
+
committed!
|
394
|
+
elsif transaction_state.rolledback?
|
395
|
+
rolledback!
|
396
|
+
end
|
416
397
|
@reflects_state[depth] = true
|
417
398
|
end
|
418
399
|
|
@@ -441,8 +422,6 @@ module ActiveRecord
|
|
441
422
|
@aggregation_cache = {}
|
442
423
|
@association_cache = {}
|
443
424
|
@attributes_cache = {}
|
444
|
-
@previously_changed = {}
|
445
|
-
@changed_attributes = {}
|
446
425
|
@readonly = false
|
447
426
|
@destroyed = false
|
448
427
|
@marked_for_destruction = false
|
@@ -459,7 +438,7 @@ module ActiveRecord
|
|
459
438
|
# optimistic locking) won't get written unless they get marked as changed
|
460
439
|
self.class.columns.each do |c|
|
461
440
|
attr, orig_value = c.name, c.default
|
462
|
-
|
441
|
+
changed_attributes[attr] = orig_value if _field_changed?(attr, orig_value, @attributes[attr])
|
463
442
|
end
|
464
443
|
end
|
465
444
|
|
@@ -34,8 +34,8 @@ module ActiveRecord
|
|
34
34
|
counter_name = reflection.counter_cache_column
|
35
35
|
|
36
36
|
stmt = unscoped.where(arel_table[primary_key].eq(object.id)).arel.compile_update({
|
37
|
-
arel_table[counter_name] => object.send(association).count
|
38
|
-
})
|
37
|
+
arel_table[counter_name] => object.send(association).count
|
38
|
+
}, primary_key)
|
39
39
|
connection.update stmt
|
40
40
|
end
|
41
41
|
return true
|
@@ -50,7 +50,7 @@ module ActiveRecord
|
|
50
50
|
# ==== Parameters
|
51
51
|
#
|
52
52
|
# * +id+ - The id of the object you wish to update a counter on or an Array of ids.
|
53
|
-
# * +counters+ -
|
53
|
+
# * +counters+ - A Hash containing the names of the fields
|
54
54
|
# to update as keys and the amount to update the field by as values.
|
55
55
|
#
|
56
56
|
# ==== Examples
|
@@ -82,10 +82,10 @@ module ActiveRecord
|
|
82
82
|
|
83
83
|
# Increment a numeric field by one, via a direct SQL update.
|
84
84
|
#
|
85
|
-
# This method is used primarily for maintaining counter_cache columns
|
86
|
-
# store aggregate values. For example, a DiscussionBoard may cache
|
87
|
-
# and comments_count to avoid running an SQL query to calculate the
|
88
|
-
# posts and comments there are each time it is displayed.
|
85
|
+
# This method is used primarily for maintaining counter_cache columns that are
|
86
|
+
# used to store aggregate values. For example, a DiscussionBoard may cache
|
87
|
+
# posts_count and comments_count to avoid running an SQL query to calculate the
|
88
|
+
# number of posts and comments there are, each time it is displayed.
|
89
89
|
#
|
90
90
|
# ==== Parameters
|
91
91
|
#
|