activerecord 4.2.1 → 4.2.7.1
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 +368 -1
- data/lib/active_record/aggregations.rb +4 -3
- data/lib/active_record/association_relation.rb +13 -0
- data/lib/active_record/associations/association.rb +15 -3
- data/lib/active_record/associations/association_scope.rb +1 -0
- data/lib/active_record/associations/belongs_to_association.rb +5 -1
- data/lib/active_record/associations/builder/association.rb +1 -1
- data/lib/active_record/associations/builder/has_and_belongs_to_many.rb +8 -4
- data/lib/active_record/associations/collection_association.rb +1 -7
- data/lib/active_record/associations/collection_proxy.rb +8 -7
- data/lib/active_record/associations/has_many_association.rb +8 -1
- data/lib/active_record/associations/has_many_through_association.rb +9 -0
- data/lib/active_record/associations/join_dependency.rb +8 -2
- data/lib/active_record/associations/preloader/association.rb +5 -1
- data/lib/active_record/associations/preloader.rb +4 -4
- data/lib/active_record/associations/singular_association.rb +2 -8
- data/lib/active_record/associations/through_association.rb +0 -6
- data/lib/active_record/associations.rb +1 -1
- data/lib/active_record/attribute_assignment.rb +1 -1
- data/lib/active_record/attribute_methods/dirty.rb +7 -1
- data/lib/active_record/attribute_methods.rb +3 -7
- data/lib/active_record/attribute_set/builder.rb +21 -11
- data/lib/active_record/attribute_set.rb +4 -0
- data/lib/active_record/autosave_association.rb +1 -1
- data/lib/active_record/base.rb +4 -5
- data/lib/active_record/callbacks.rb +1 -1
- data/lib/active_record/connection_adapters/abstract/connection_pool.rb +4 -0
- data/lib/active_record/connection_adapters/abstract/database_statements.rb +11 -2
- data/lib/active_record/connection_adapters/abstract/schema_definitions.rb +16 -24
- data/lib/active_record/connection_adapters/abstract/schema_statements.rb +49 -17
- data/lib/active_record/connection_adapters/abstract/transaction.rb +1 -5
- data/lib/active_record/connection_adapters/abstract_adapter.rb +12 -1
- data/lib/active_record/connection_adapters/abstract_mysql_adapter.rb +38 -5
- data/lib/active_record/connection_adapters/column.rb +1 -1
- data/lib/active_record/connection_adapters/mysql2_adapter.rb +3 -3
- data/lib/active_record/connection_adapters/mysql_adapter.rb +2 -2
- data/lib/active_record/connection_adapters/postgresql/oid/array.rb +1 -1
- data/lib/active_record/connection_adapters/postgresql/oid/enum.rb +3 -1
- data/lib/active_record/connection_adapters/postgresql/oid/type_map_initializer.rb +17 -5
- data/lib/active_record/connection_adapters/postgresql/schema_statements.rb +15 -6
- data/lib/active_record/connection_adapters/postgresql_adapter.rb +9 -9
- data/lib/active_record/connection_adapters/sqlite3_adapter.rb +2 -12
- data/lib/active_record/core.rb +15 -8
- data/lib/active_record/enum.rb +2 -3
- data/lib/active_record/errors.rb +6 -5
- data/lib/active_record/explain_subscriber.rb +1 -1
- data/lib/active_record/fixtures.rb +8 -6
- data/lib/active_record/gem_version.rb +2 -2
- data/lib/active_record/legacy_yaml_adapter.rb +30 -0
- data/lib/active_record/migration.rb +7 -4
- data/lib/active_record/model_schema.rb +1 -1
- data/lib/active_record/nested_attributes.rb +12 -2
- data/lib/active_record/persistence.rb +5 -3
- data/lib/active_record/railtie.rb +1 -1
- data/lib/active_record/railties/databases.rake +10 -7
- data/lib/active_record/reflection.rb +39 -27
- data/lib/active_record/relation/calculations.rb +8 -1
- data/lib/active_record/relation/delegation.rb +1 -1
- data/lib/active_record/relation/finder_methods.rb +3 -15
- data/lib/active_record/relation/merger.rb +24 -1
- data/lib/active_record/relation/predicate_builder/array_handler.rb +2 -1
- data/lib/active_record/relation/predicate_builder.rb +11 -2
- data/lib/active_record/relation/query_methods.rb +15 -18
- data/lib/active_record/relation/spawn_methods.rb +7 -3
- data/lib/active_record/relation.rb +2 -1
- data/lib/active_record/scoping/default.rb +1 -0
- data/lib/active_record/tasks/database_tasks.rb +3 -2
- data/lib/active_record/tasks/mysql_database_tasks.rb +30 -16
- data/lib/active_record/tasks/postgresql_database_tasks.rb +19 -8
- data/lib/active_record/transactions.rb +16 -4
- data/lib/active_record/type/boolean.rb +1 -0
- data/lib/active_record/type/date.rb +4 -0
- data/lib/active_record/type/decimal.rb +12 -2
- data/lib/active_record/type/hash_lookup_type_map.rb +8 -2
- data/lib/active_record/type/serialized.rb +7 -1
- data/lib/active_record/validations/uniqueness.rb +15 -5
- data/lib/active_record.rb +2 -0
- metadata +9 -7
@@ -328,9 +328,13 @@ module ActiveRecord
|
|
328
328
|
# Add the record to the current transaction so that the +after_rollback+ and +after_commit+ callbacks
|
329
329
|
# can be called.
|
330
330
|
def add_to_transaction
|
331
|
-
if
|
332
|
-
|
331
|
+
if has_transactional_callbacks?
|
332
|
+
self.class.connection.add_transaction_record(self)
|
333
|
+
else
|
334
|
+
sync_with_transaction_state
|
335
|
+
set_transaction_state(self.class.connection.transaction_state)
|
333
336
|
end
|
337
|
+
remember_transaction_record_state
|
334
338
|
end
|
335
339
|
|
336
340
|
# Executes +method+ within a transaction and captures its return value as a
|
@@ -353,6 +357,10 @@ module ActiveRecord
|
|
353
357
|
raise ActiveRecord::Rollback unless status
|
354
358
|
end
|
355
359
|
status
|
360
|
+
ensure
|
361
|
+
if @transaction_state && @transaction_state.committed?
|
362
|
+
clear_transaction_record_state
|
363
|
+
end
|
356
364
|
end
|
357
365
|
|
358
366
|
protected
|
@@ -385,10 +393,14 @@ module ActiveRecord
|
|
385
393
|
transaction_level = (@_start_transaction_state[:level] || 0) - 1
|
386
394
|
if transaction_level < 1 || force
|
387
395
|
restore_state = @_start_transaction_state
|
388
|
-
thaw
|
396
|
+
thaw
|
389
397
|
@new_record = restore_state[:new_record]
|
390
398
|
@destroyed = restore_state[:destroyed]
|
391
|
-
|
399
|
+
pk = self.class.primary_key
|
400
|
+
if pk && read_attribute(pk) != restore_state[:id]
|
401
|
+
write_attribute(pk, restore_state[:id])
|
402
|
+
end
|
403
|
+
freeze if restore_state[:frozen?]
|
392
404
|
end
|
393
405
|
end
|
394
406
|
end
|
@@ -16,6 +16,7 @@ module ActiveRecord
|
|
16
16
|
if !ConnectionAdapters::Column::FALSE_VALUES.include?(value)
|
17
17
|
ActiveSupport::Deprecation.warn(<<-MSG.squish)
|
18
18
|
You attempted to assign a value which is not explicitly `true` or `false`
|
19
|
+
(#{value.inspect})
|
19
20
|
to a boolean column. Currently this value casts to `false`. This will
|
20
21
|
change to match Ruby's semantics, and will cast to `true` in Rails 5.
|
21
22
|
If you would like to maintain the current behavior, you should
|
@@ -14,7 +14,7 @@ module ActiveRecord
|
|
14
14
|
private
|
15
15
|
|
16
16
|
def cast_value(value)
|
17
|
-
case value
|
17
|
+
casted_value = case value
|
18
18
|
when ::Float
|
19
19
|
convert_float_to_big_decimal(value)
|
20
20
|
when ::Numeric, ::String
|
@@ -26,11 +26,13 @@ module ActiveRecord
|
|
26
26
|
cast_value(value.to_s)
|
27
27
|
end
|
28
28
|
end
|
29
|
+
|
30
|
+
apply_scale(casted_value)
|
29
31
|
end
|
30
32
|
|
31
33
|
def convert_float_to_big_decimal(value)
|
32
34
|
if precision
|
33
|
-
BigDecimal(value, float_precision)
|
35
|
+
BigDecimal(apply_scale(value), float_precision)
|
34
36
|
else
|
35
37
|
value.to_d
|
36
38
|
end
|
@@ -43,6 +45,14 @@ module ActiveRecord
|
|
43
45
|
precision.to_i
|
44
46
|
end
|
45
47
|
end
|
48
|
+
|
49
|
+
def apply_scale(value)
|
50
|
+
if scale
|
51
|
+
value.round(scale)
|
52
|
+
else
|
53
|
+
value
|
54
|
+
end
|
55
|
+
end
|
46
56
|
end
|
47
57
|
end
|
48
58
|
end
|
@@ -1,12 +1,18 @@
|
|
1
1
|
module ActiveRecord
|
2
2
|
module Type
|
3
3
|
class HashLookupTypeMap < TypeMap # :nodoc:
|
4
|
-
delegate :key?, to: :@mapping
|
5
|
-
|
6
4
|
def alias_type(type, alias_type)
|
7
5
|
register_type(type) { |_, *args| lookup(alias_type, *args) }
|
8
6
|
end
|
9
7
|
|
8
|
+
def key?(key)
|
9
|
+
@mapping.key?(key)
|
10
|
+
end
|
11
|
+
|
12
|
+
def keys
|
13
|
+
@mapping.keys
|
14
|
+
end
|
15
|
+
|
10
16
|
private
|
11
17
|
|
12
18
|
def perform_fetch(type, *args, &block)
|
@@ -27,9 +27,15 @@ module ActiveRecord
|
|
27
27
|
end
|
28
28
|
end
|
29
29
|
|
30
|
+
def inspect
|
31
|
+
Kernel.instance_method(:inspect).bind(self).call
|
32
|
+
end
|
33
|
+
|
30
34
|
def changed_in_place?(raw_old_value, value)
|
31
35
|
return false if value.nil?
|
32
|
-
|
36
|
+
raw_new_value = type_cast_for_database(value)
|
37
|
+
raw_old_value.nil? != raw_new_value.nil? ||
|
38
|
+
subtype.changed_in_place?(raw_old_value, raw_new_value)
|
33
39
|
end
|
34
40
|
|
35
41
|
def accessor
|
@@ -15,11 +15,21 @@ module ActiveRecord
|
|
15
15
|
table = finder_class.arel_table
|
16
16
|
value = map_enum_attribute(finder_class, attribute, value)
|
17
17
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
18
|
+
begin
|
19
|
+
relation = build_relation(finder_class, table, attribute, value)
|
20
|
+
if record.persisted?
|
21
|
+
if finder_class.primary_key
|
22
|
+
relation = relation.and(table[finder_class.primary_key.to_sym].not_eq(record.id))
|
23
|
+
else
|
24
|
+
raise UnknownPrimaryKey.new(finder_class, "Can not validate uniqueness for persisted record without primary key.")
|
25
|
+
end
|
26
|
+
end
|
27
|
+
relation = scope_relation(record, table, relation)
|
28
|
+
relation = finder_class.unscoped.where(relation)
|
29
|
+
relation = relation.merge(options[:conditions]) if options[:conditions]
|
30
|
+
rescue RangeError
|
31
|
+
relation = finder_class.none
|
32
|
+
end
|
23
33
|
|
24
34
|
if relation.exists?
|
25
35
|
error_options = options.except(:case_sensitive, :scope, :conditions)
|
data/lib/active_record.rb
CHANGED
@@ -43,6 +43,7 @@ module ActiveRecord
|
|
43
43
|
autoload :Explain
|
44
44
|
autoload :Inheritance
|
45
45
|
autoload :Integration
|
46
|
+
autoload :LegacyYamlAdapter
|
46
47
|
autoload :Migration
|
47
48
|
autoload :Migrator, 'active_record/migration'
|
48
49
|
autoload :ModelSchema
|
@@ -52,6 +53,7 @@ module ActiveRecord
|
|
52
53
|
autoload :QueryCache
|
53
54
|
autoload :Querying
|
54
55
|
autoload :ReadonlyAttributes
|
56
|
+
autoload :RecordInvalid, 'active_record/validations'
|
55
57
|
autoload :Reflection
|
56
58
|
autoload :RuntimeRegistry
|
57
59
|
autoload :Sanitization
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: activerecord
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 4.2.1
|
4
|
+
version: 4.2.7.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- David Heinemeier Hansson
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2016-08-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -16,28 +16,28 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - '='
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 4.2.1
|
19
|
+
version: 4.2.7.1
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - '='
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: 4.2.1
|
26
|
+
version: 4.2.7.1
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: activemodel
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - '='
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: 4.2.1
|
33
|
+
version: 4.2.7.1
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - '='
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: 4.2.1
|
40
|
+
version: 4.2.7.1
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: arel
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -194,6 +194,7 @@ files:
|
|
194
194
|
- lib/active_record/gem_version.rb
|
195
195
|
- lib/active_record/inheritance.rb
|
196
196
|
- lib/active_record/integration.rb
|
197
|
+
- lib/active_record/legacy_yaml_adapter.rb
|
197
198
|
- lib/active_record/locale/en.yml
|
198
199
|
- lib/active_record/locking/optimistic.rb
|
199
200
|
- lib/active_record/locking/pessimistic.rb
|
@@ -303,8 +304,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
303
304
|
version: '0'
|
304
305
|
requirements: []
|
305
306
|
rubyforge_project:
|
306
|
-
rubygems_version: 2.
|
307
|
+
rubygems_version: 2.6.6
|
307
308
|
signing_key:
|
308
309
|
specification_version: 4
|
309
310
|
summary: Object-relational mapper framework (part of Rails).
|
310
311
|
test_files: []
|
312
|
+
has_rdoc:
|