activerecord 4.2.0 → 4.2.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of activerecord might be problematic. Click here for more details.
- checksums.yaml +5 -5
- data/CHANGELOG.md +657 -1
- data/lib/active_record.rb +3 -0
- data/lib/active_record/aggregations.rb +6 -3
- data/lib/active_record/association_relation.rb +13 -0
- data/lib/active_record/associations.rb +5 -4
- 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 +13 -5
- data/lib/active_record/associations/builder/association.rb +1 -1
- data/lib/active_record/associations/builder/collection_association.rb +5 -1
- data/lib/active_record/associations/builder/has_and_belongs_to_many.rb +8 -4
- data/lib/active_record/associations/collection_association.rb +35 -15
- data/lib/active_record/associations/collection_proxy.rb +15 -9
- data/lib/active_record/associations/foreign_association.rb +11 -0
- data/lib/active_record/associations/has_many_association.rb +30 -15
- data/lib/active_record/associations/has_many_through_association.rb +11 -2
- data/lib/active_record/associations/has_one_association.rb +1 -0
- data/lib/active_record/associations/join_dependency.rb +8 -2
- data/lib/active_record/associations/join_dependency/join_association.rb +7 -1
- data/lib/active_record/associations/preloader.rb +4 -4
- data/lib/active_record/associations/preloader/association.rb +5 -1
- data/lib/active_record/associations/singular_association.rb +2 -8
- data/lib/active_record/associations/through_association.rb +11 -6
- data/lib/active_record/attribute.rb +15 -1
- data/lib/active_record/attribute_assignment.rb +2 -2
- data/lib/active_record/attribute_methods.rb +4 -8
- data/lib/active_record/attribute_methods/before_type_cast.rb +5 -0
- data/lib/active_record/attribute_methods/dirty.rb +14 -4
- data/lib/active_record/attribute_methods/time_zone_conversion.rb +5 -1
- data/lib/active_record/attribute_methods/write.rb +1 -1
- data/lib/active_record/attribute_set.rb +4 -0
- data/lib/active_record/attribute_set/builder.rb +32 -12
- data/lib/active_record/attributes.rb +8 -0
- data/lib/active_record/autosave_association.rb +24 -9
- 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 +12 -6
- data/lib/active_record/connection_adapters/abstract/database_statements.rb +23 -3
- data/lib/active_record/connection_adapters/abstract/query_cache.rb +1 -1
- data/lib/active_record/connection_adapters/abstract/quoting.rb +1 -0
- data/lib/active_record/connection_adapters/abstract/savepoints.rb +1 -1
- data/lib/active_record/connection_adapters/abstract/schema_definitions.rb +26 -16
- data/lib/active_record/connection_adapters/abstract/schema_statements.rb +87 -24
- data/lib/active_record/connection_adapters/abstract/transaction.rb +2 -6
- data/lib/active_record/connection_adapters/abstract_adapter.rb +25 -7
- data/lib/active_record/connection_adapters/abstract_mysql_adapter.rb +73 -10
- data/lib/active_record/connection_adapters/column.rb +2 -2
- data/lib/active_record/connection_adapters/mysql2_adapter.rb +7 -21
- data/lib/active_record/connection_adapters/mysql_adapter.rb +10 -3
- data/lib/active_record/connection_adapters/postgresql/database_statements.rb +1 -1
- data/lib/active_record/connection_adapters/postgresql/oid/array.rb +2 -1
- data/lib/active_record/connection_adapters/postgresql/oid/bytea.rb +1 -0
- data/lib/active_record/connection_adapters/postgresql/oid/date_time.rb +9 -0
- data/lib/active_record/connection_adapters/postgresql/oid/enum.rb +3 -1
- data/lib/active_record/connection_adapters/postgresql/oid/json.rb +1 -1
- data/lib/active_record/connection_adapters/postgresql/oid/specialized_string.rb +4 -0
- data/lib/active_record/connection_adapters/postgresql/oid/type_map_initializer.rb +17 -5
- data/lib/active_record/connection_adapters/postgresql/schema_definitions.rb +3 -3
- data/lib/active_record/connection_adapters/postgresql/schema_statements.rb +21 -13
- data/lib/active_record/connection_adapters/postgresql_adapter.rb +12 -12
- data/lib/active_record/connection_adapters/sqlite3_adapter.rb +12 -28
- data/lib/active_record/connection_handling.rb +1 -1
- data/lib/active_record/core.rb +28 -15
- data/lib/active_record/counter_cache.rb +1 -1
- 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 +9 -7
- data/lib/active_record/gem_version.rb +1 -1
- data/lib/active_record/legacy_yaml_adapter.rb +30 -0
- data/lib/active_record/locking/optimistic.rb +16 -14
- data/lib/active_record/migration.rb +38 -10
- data/lib/active_record/model_schema.rb +4 -2
- data/lib/active_record/nested_attributes.rb +13 -3
- data/lib/active_record/no_touching.rb +1 -1
- data/lib/active_record/persistence.rb +7 -4
- data/lib/active_record/railtie.rb +5 -3
- data/lib/active_record/railties/databases.rake +17 -24
- data/lib/active_record/reflection.rb +40 -28
- data/lib/active_record/relation.rb +3 -2
- data/lib/active_record/relation/calculations.rb +10 -3
- data/lib/active_record/relation/delegation.rb +1 -1
- data/lib/active_record/relation/finder_methods.rb +4 -16
- data/lib/active_record/relation/merger.rb +24 -1
- data/lib/active_record/relation/predicate_builder.rb +32 -3
- data/lib/active_record/relation/predicate_builder/array_handler.rb +3 -2
- data/lib/active_record/relation/query_methods.rb +29 -27
- data/lib/active_record/relation/spawn_methods.rb +7 -3
- data/lib/active_record/schema_dumper.rb +1 -1
- data/lib/active_record/schema_migration.rb +1 -4
- data/lib/active_record/scoping/default.rb +1 -0
- data/lib/active_record/tasks/database_tasks.rb +5 -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 +21 -11
- data/lib/active_record/type/boolean.rb +1 -0
- data/lib/active_record/type/date.rb +4 -0
- data/lib/active_record/type/date_time.rb +14 -3
- data/lib/active_record/type/decimal.rb +27 -3
- data/lib/active_record/type/hash_lookup_type_map.rb +8 -2
- data/lib/active_record/type/integer.rb +9 -5
- data/lib/active_record/type/numeric.rb +1 -1
- data/lib/active_record/type/serialized.rb +7 -1
- data/lib/active_record/type/string.rb +4 -0
- data/lib/active_record/type/value.rb +9 -0
- data/lib/active_record/validations/uniqueness.rb +16 -6
- data/lib/rails/generators/active_record/migration/templates/create_table_migration.rb +0 -3
- data/lib/rails/generators/active_record/migration/templates/migration.rb +0 -6
- metadata +9 -7
|
@@ -14,11 +14,17 @@ 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
|
-
|
|
20
|
-
when ::Numeric
|
|
19
|
+
convert_float_to_big_decimal(value)
|
|
20
|
+
when ::Numeric
|
|
21
21
|
BigDecimal(value, precision.to_i)
|
|
22
|
+
when ::String
|
|
23
|
+
begin
|
|
24
|
+
value.to_d
|
|
25
|
+
rescue ArgumentError
|
|
26
|
+
BigDecimal(0)
|
|
27
|
+
end
|
|
22
28
|
else
|
|
23
29
|
if value.respond_to?(:to_d)
|
|
24
30
|
value.to_d
|
|
@@ -26,6 +32,16 @@ module ActiveRecord
|
|
|
26
32
|
cast_value(value.to_s)
|
|
27
33
|
end
|
|
28
34
|
end
|
|
35
|
+
|
|
36
|
+
apply_scale(casted_value)
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def convert_float_to_big_decimal(value)
|
|
40
|
+
if precision
|
|
41
|
+
BigDecimal(apply_scale(value), float_precision)
|
|
42
|
+
else
|
|
43
|
+
value.to_d
|
|
44
|
+
end
|
|
29
45
|
end
|
|
30
46
|
|
|
31
47
|
def float_precision
|
|
@@ -35,6 +51,14 @@ module ActiveRecord
|
|
|
35
51
|
precision.to_i
|
|
36
52
|
end
|
|
37
53
|
end
|
|
54
|
+
|
|
55
|
+
def apply_scale(value)
|
|
56
|
+
if scale
|
|
57
|
+
value.round(scale)
|
|
58
|
+
else
|
|
59
|
+
value
|
|
60
|
+
end
|
|
61
|
+
end
|
|
38
62
|
end
|
|
39
63
|
end
|
|
40
64
|
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)
|
|
@@ -12,13 +12,19 @@ module ActiveRecord
|
|
|
12
12
|
:integer
|
|
13
13
|
end
|
|
14
14
|
|
|
15
|
-
alias type_cast_for_database type_cast
|
|
16
|
-
|
|
17
15
|
def type_cast_from_database(value)
|
|
18
16
|
return if value.nil?
|
|
19
17
|
value.to_i
|
|
20
18
|
end
|
|
21
19
|
|
|
20
|
+
def type_cast_for_database(value)
|
|
21
|
+
result = type_cast(value)
|
|
22
|
+
if result
|
|
23
|
+
ensure_in_range(result)
|
|
24
|
+
end
|
|
25
|
+
result
|
|
26
|
+
end
|
|
27
|
+
|
|
22
28
|
protected
|
|
23
29
|
|
|
24
30
|
attr_reader :range
|
|
@@ -30,9 +36,7 @@ module ActiveRecord
|
|
|
30
36
|
when true then 1
|
|
31
37
|
when false then 0
|
|
32
38
|
else
|
|
33
|
-
|
|
34
|
-
ensure_in_range(result) if result
|
|
35
|
-
result
|
|
39
|
+
value.to_i rescue nil
|
|
36
40
|
end
|
|
37
41
|
end
|
|
38
42
|
|
|
@@ -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
|
|
@@ -50,6 +50,10 @@ module ActiveRecord
|
|
|
50
50
|
|
|
51
51
|
# These predicates are not documented, as I need to look further into
|
|
52
52
|
# their use, and see if they can be removed entirely.
|
|
53
|
+
def text? # :nodoc:
|
|
54
|
+
false
|
|
55
|
+
end
|
|
56
|
+
|
|
53
57
|
def number? # :nodoc:
|
|
54
58
|
false
|
|
55
59
|
end
|
|
@@ -82,6 +86,11 @@ module ActiveRecord
|
|
|
82
86
|
scale == other.scale &&
|
|
83
87
|
limit == other.limit
|
|
84
88
|
end
|
|
89
|
+
alias eql? ==
|
|
90
|
+
|
|
91
|
+
def hash
|
|
92
|
+
[self.class, precision, scale, limit].hash
|
|
93
|
+
end
|
|
85
94
|
|
|
86
95
|
private
|
|
87
96
|
|
|
@@ -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)
|
|
@@ -65,7 +75,7 @@ module ActiveRecord
|
|
|
65
75
|
value = value.to_s[0, column.limit]
|
|
66
76
|
end
|
|
67
77
|
|
|
68
|
-
if !options[:case_sensitive] && value.
|
|
78
|
+
if !options[:case_sensitive] && value && column.text?
|
|
69
79
|
# will use SQL LOWER function before comparison, unless it detects a case insensitive collation
|
|
70
80
|
klass.connection.case_insensitive_comparison(table, attribute, column, value)
|
|
71
81
|
else
|
|
@@ -14,9 +14,6 @@ class <%= migration_class_name %> < ActiveRecord::Migration
|
|
|
14
14
|
end
|
|
15
15
|
<% attributes_with_index.each do |attribute| -%>
|
|
16
16
|
add_index :<%= table_name %>, :<%= attribute.index_name %><%= attribute.inject_index_options %>
|
|
17
|
-
<% end -%>
|
|
18
|
-
<% attributes.select(&:reference?).reject(&:polymorphic?).each do |attribute| -%>
|
|
19
|
-
add_foreign_key :<%= table_name %>, :<%= attribute.name.pluralize %>
|
|
20
17
|
<% end -%>
|
|
21
18
|
end
|
|
22
19
|
end
|
|
@@ -4,9 +4,6 @@ class <%= migration_class_name %> < ActiveRecord::Migration
|
|
|
4
4
|
<% attributes.each do |attribute| -%>
|
|
5
5
|
<%- if attribute.reference? -%>
|
|
6
6
|
add_reference :<%= table_name %>, :<%= attribute.name %><%= attribute.inject_options %>
|
|
7
|
-
<%- unless attribute.polymorphic? -%>
|
|
8
|
-
add_foreign_key :<%= table_name %>, :<%= attribute.name.pluralize %>
|
|
9
|
-
<%- end -%>
|
|
10
7
|
<%- else -%>
|
|
11
8
|
add_column :<%= table_name %>, :<%= attribute.name %>, :<%= attribute.type %><%= attribute.inject_options %>
|
|
12
9
|
<%- if attribute.has_index? -%>
|
|
@@ -29,9 +26,6 @@ class <%= migration_class_name %> < ActiveRecord::Migration
|
|
|
29
26
|
<%- if migration_action -%>
|
|
30
27
|
<%- if attribute.reference? -%>
|
|
31
28
|
remove_reference :<%= table_name %>, :<%= attribute.name %><%= attribute.inject_options %>
|
|
32
|
-
<%- unless attribute.polymorphic? -%>
|
|
33
|
-
remove_foreign_key :<%= table_name %>, :<%= attribute.name.pluralize %>
|
|
34
|
-
<%- end -%>
|
|
35
29
|
<%- else -%>
|
|
36
30
|
<%- if attribute.has_index? -%>
|
|
37
31
|
remove_index :<%= table_name %>, :<%= attribute.index_name %><%= attribute.inject_index_options %>
|
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.
|
|
4
|
+
version: 4.2.11
|
|
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: 2018-11-27 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.
|
|
19
|
+
version: 4.2.11
|
|
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.
|
|
26
|
+
version: 4.2.11
|
|
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.
|
|
33
|
+
version: 4.2.11
|
|
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.
|
|
40
|
+
version: 4.2.11
|
|
41
41
|
- !ruby/object:Gem::Dependency
|
|
42
42
|
name: arel
|
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -84,6 +84,7 @@ files:
|
|
|
84
84
|
- lib/active_record/associations/builder/singular_association.rb
|
|
85
85
|
- lib/active_record/associations/collection_association.rb
|
|
86
86
|
- lib/active_record/associations/collection_proxy.rb
|
|
87
|
+
- lib/active_record/associations/foreign_association.rb
|
|
87
88
|
- lib/active_record/associations/has_many_association.rb
|
|
88
89
|
- lib/active_record/associations/has_many_through_association.rb
|
|
89
90
|
- lib/active_record/associations/has_one_association.rb
|
|
@@ -193,6 +194,7 @@ files:
|
|
|
193
194
|
- lib/active_record/gem_version.rb
|
|
194
195
|
- lib/active_record/inheritance.rb
|
|
195
196
|
- lib/active_record/integration.rb
|
|
197
|
+
- lib/active_record/legacy_yaml_adapter.rb
|
|
196
198
|
- lib/active_record/locale/en.yml
|
|
197
199
|
- lib/active_record/locking/optimistic.rb
|
|
198
200
|
- lib/active_record/locking/pessimistic.rb
|
|
@@ -302,7 +304,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
302
304
|
version: '0'
|
|
303
305
|
requirements: []
|
|
304
306
|
rubyforge_project:
|
|
305
|
-
rubygems_version: 2.
|
|
307
|
+
rubygems_version: 2.7.6
|
|
306
308
|
signing_key:
|
|
307
309
|
specification_version: 4
|
|
308
310
|
summary: Object-relational mapper framework (part of Rails).
|