activerecord 5.2.4.rc1 → 6.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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +597 -586
- data/MIT-LICENSE +3 -1
- data/README.rdoc +4 -2
- data/examples/performance.rb +1 -1
- data/lib/active_record.rb +9 -2
- data/lib/active_record/aggregations.rb +4 -2
- data/lib/active_record/associations.rb +19 -14
- data/lib/active_record/associations/association.rb +52 -19
- data/lib/active_record/associations/association_scope.rb +4 -6
- data/lib/active_record/associations/belongs_to_association.rb +36 -42
- data/lib/active_record/associations/belongs_to_polymorphic_association.rb +0 -4
- data/lib/active_record/associations/builder/association.rb +14 -18
- data/lib/active_record/associations/builder/belongs_to.rb +19 -52
- data/lib/active_record/associations/builder/collection_association.rb +3 -13
- data/lib/active_record/associations/builder/has_and_belongs_to_many.rb +17 -38
- data/lib/active_record/associations/builder/has_many.rb +2 -0
- data/lib/active_record/associations/builder/has_one.rb +35 -1
- data/lib/active_record/associations/builder/singular_association.rb +2 -0
- data/lib/active_record/associations/collection_association.rb +6 -21
- data/lib/active_record/associations/collection_proxy.rb +12 -15
- data/lib/active_record/associations/foreign_association.rb +7 -0
- data/lib/active_record/associations/has_many_association.rb +2 -10
- data/lib/active_record/associations/has_many_through_association.rb +14 -14
- data/lib/active_record/associations/has_one_association.rb +28 -30
- data/lib/active_record/associations/has_one_through_association.rb +5 -5
- data/lib/active_record/associations/join_dependency.rb +24 -28
- data/lib/active_record/associations/join_dependency/join_association.rb +9 -10
- data/lib/active_record/associations/join_dependency/join_part.rb +2 -2
- data/lib/active_record/associations/preloader.rb +40 -32
- data/lib/active_record/associations/preloader/association.rb +38 -36
- data/lib/active_record/associations/preloader/through_association.rb +48 -39
- data/lib/active_record/associations/singular_association.rb +2 -16
- data/lib/active_record/attribute_assignment.rb +7 -10
- data/lib/active_record/attribute_methods.rb +28 -100
- data/lib/active_record/attribute_methods/before_type_cast.rb +4 -1
- data/lib/active_record/attribute_methods/dirty.rb +111 -40
- data/lib/active_record/attribute_methods/primary_key.rb +15 -22
- data/lib/active_record/attribute_methods/query.rb +2 -3
- data/lib/active_record/attribute_methods/read.rb +15 -53
- data/lib/active_record/attribute_methods/serialization.rb +1 -1
- data/lib/active_record/attribute_methods/time_zone_conversion.rb +1 -1
- data/lib/active_record/attribute_methods/write.rb +17 -24
- data/lib/active_record/attributes.rb +13 -0
- data/lib/active_record/autosave_association.rb +5 -9
- data/lib/active_record/base.rb +2 -3
- data/lib/active_record/callbacks.rb +5 -19
- data/lib/active_record/connection_adapters/abstract/connection_pool.rb +89 -16
- data/lib/active_record/connection_adapters/abstract/database_limits.rb +17 -4
- data/lib/active_record/connection_adapters/abstract/database_statements.rb +95 -123
- data/lib/active_record/connection_adapters/abstract/query_cache.rb +17 -8
- data/lib/active_record/connection_adapters/abstract/quoting.rb +68 -17
- data/lib/active_record/connection_adapters/abstract/schema_creation.rb +19 -12
- data/lib/active_record/connection_adapters/abstract/schema_definitions.rb +76 -48
- data/lib/active_record/connection_adapters/abstract/schema_dumper.rb +1 -3
- data/lib/active_record/connection_adapters/abstract/schema_statements.rb +133 -54
- data/lib/active_record/connection_adapters/abstract/transaction.rb +96 -56
- data/lib/active_record/connection_adapters/abstract_adapter.rb +172 -41
- data/lib/active_record/connection_adapters/abstract_mysql_adapter.rb +128 -194
- data/lib/active_record/connection_adapters/column.rb +17 -13
- data/lib/active_record/connection_adapters/connection_specification.rb +52 -42
- data/lib/active_record/connection_adapters/determine_if_preparable_visitor.rb +6 -10
- data/lib/active_record/connection_adapters/mysql/database_statements.rb +73 -13
- data/lib/active_record/connection_adapters/mysql/quoting.rb +44 -7
- data/lib/active_record/connection_adapters/mysql/schema_creation.rb +3 -4
- data/lib/active_record/connection_adapters/mysql/schema_definitions.rb +40 -32
- data/lib/active_record/connection_adapters/mysql/schema_dumper.rb +14 -6
- data/lib/active_record/connection_adapters/mysql/schema_statements.rb +129 -13
- data/lib/active_record/connection_adapters/mysql/type_metadata.rb +6 -10
- data/lib/active_record/connection_adapters/mysql2_adapter.rb +24 -7
- data/lib/active_record/connection_adapters/postgresql/column.rb +17 -31
- data/lib/active_record/connection_adapters/postgresql/database_statements.rb +20 -1
- data/lib/active_record/connection_adapters/postgresql/oid/array.rb +1 -1
- data/lib/active_record/connection_adapters/postgresql/oid/bit.rb +1 -4
- data/lib/active_record/connection_adapters/postgresql/oid/hstore.rb +1 -1
- data/lib/active_record/connection_adapters/postgresql/oid/legacy_point.rb +1 -1
- data/lib/active_record/connection_adapters/postgresql/oid/point.rb +1 -1
- data/lib/active_record/connection_adapters/postgresql/oid/range.rb +1 -1
- data/lib/active_record/connection_adapters/postgresql/oid/type_map_initializer.rb +9 -7
- data/lib/active_record/connection_adapters/postgresql/oid/uuid.rb +6 -3
- data/lib/active_record/connection_adapters/postgresql/quoting.rb +44 -7
- data/lib/active_record/connection_adapters/postgresql/schema_creation.rb +12 -1
- data/lib/active_record/connection_adapters/postgresql/schema_definitions.rb +107 -91
- data/lib/active_record/connection_adapters/postgresql/schema_statements.rb +55 -53
- data/lib/active_record/connection_adapters/postgresql/type_metadata.rb +24 -27
- data/lib/active_record/connection_adapters/postgresql_adapter.rb +160 -74
- data/lib/active_record/connection_adapters/schema_cache.rb +37 -14
- data/lib/active_record/connection_adapters/sql_type_metadata.rb +11 -8
- data/lib/active_record/connection_adapters/sqlite3/database_statements.rb +118 -0
- data/lib/active_record/connection_adapters/sqlite3/quoting.rb +42 -6
- data/lib/active_record/connection_adapters/sqlite3/schema_statements.rb +42 -11
- data/lib/active_record/connection_adapters/sqlite3_adapter.rb +125 -141
- data/lib/active_record/connection_handling.rb +149 -27
- data/lib/active_record/core.rb +100 -60
- data/lib/active_record/counter_cache.rb +4 -29
- data/lib/active_record/database_configurations.rb +204 -0
- data/lib/active_record/database_configurations/database_config.rb +37 -0
- data/lib/active_record/database_configurations/hash_config.rb +50 -0
- data/lib/active_record/database_configurations/url_config.rb +79 -0
- data/lib/active_record/dynamic_matchers.rb +1 -1
- data/lib/active_record/enum.rb +28 -7
- data/lib/active_record/errors.rb +15 -7
- data/lib/active_record/explain.rb +1 -1
- data/lib/active_record/fixture_set/model_metadata.rb +33 -0
- data/lib/active_record/fixture_set/render_context.rb +17 -0
- data/lib/active_record/fixture_set/table_row.rb +153 -0
- data/lib/active_record/fixture_set/table_rows.rb +47 -0
- data/lib/active_record/fixtures.rb +140 -472
- data/lib/active_record/gem_version.rb +4 -4
- data/lib/active_record/inheritance.rb +13 -3
- data/lib/active_record/insert_all.rb +180 -0
- data/lib/active_record/integration.rb +68 -16
- data/lib/active_record/internal_metadata.rb +10 -2
- data/lib/active_record/locking/optimistic.rb +5 -6
- data/lib/active_record/locking/pessimistic.rb +3 -3
- data/lib/active_record/log_subscriber.rb +7 -26
- data/lib/active_record/middleware/database_selector.rb +75 -0
- data/lib/active_record/middleware/database_selector/resolver.rb +90 -0
- data/lib/active_record/middleware/database_selector/resolver/session.rb +45 -0
- data/lib/active_record/migration.rb +87 -76
- data/lib/active_record/migration/command_recorder.rb +50 -6
- data/lib/active_record/migration/compatibility.rb +76 -49
- data/lib/active_record/model_schema.rb +30 -9
- data/lib/active_record/nested_attributes.rb +2 -2
- data/lib/active_record/no_touching.rb +7 -0
- data/lib/active_record/persistence.rb +228 -24
- data/lib/active_record/query_cache.rb +11 -4
- data/lib/active_record/querying.rb +32 -20
- data/lib/active_record/railtie.rb +80 -43
- data/lib/active_record/railties/collection_cache_association_loading.rb +34 -0
- data/lib/active_record/railties/controller_runtime.rb +30 -35
- data/lib/active_record/railties/databases.rake +193 -46
- data/lib/active_record/reflection.rb +32 -30
- data/lib/active_record/relation.rb +310 -80
- data/lib/active_record/relation/batches.rb +13 -10
- data/lib/active_record/relation/calculations.rb +53 -45
- data/lib/active_record/relation/delegation.rb +26 -43
- data/lib/active_record/relation/finder_methods.rb +13 -26
- data/lib/active_record/relation/merger.rb +11 -20
- data/lib/active_record/relation/predicate_builder.rb +4 -6
- data/lib/active_record/relation/predicate_builder/array_handler.rb +5 -4
- data/lib/active_record/relation/predicate_builder/association_query_value.rb +1 -4
- data/lib/active_record/relation/predicate_builder/base_handler.rb +1 -2
- data/lib/active_record/relation/predicate_builder/basic_object_handler.rb +1 -2
- data/lib/active_record/relation/predicate_builder/polymorphic_array_value.rb +1 -4
- data/lib/active_record/relation/predicate_builder/range_handler.rb +3 -23
- data/lib/active_record/relation/query_attribute.rb +13 -8
- data/lib/active_record/relation/query_methods.rb +165 -53
- data/lib/active_record/relation/spawn_methods.rb +1 -1
- data/lib/active_record/relation/where_clause.rb +14 -10
- data/lib/active_record/relation/where_clause_factory.rb +1 -2
- data/lib/active_record/result.rb +30 -11
- data/lib/active_record/sanitization.rb +32 -40
- data/lib/active_record/schema.rb +2 -11
- data/lib/active_record/schema_dumper.rb +22 -7
- data/lib/active_record/schema_migration.rb +5 -1
- data/lib/active_record/scoping.rb +8 -8
- data/lib/active_record/scoping/default.rb +4 -5
- data/lib/active_record/scoping/named.rb +19 -15
- data/lib/active_record/statement_cache.rb +30 -3
- data/lib/active_record/store.rb +87 -8
- data/lib/active_record/table_metadata.rb +10 -17
- data/lib/active_record/tasks/database_tasks.rb +159 -25
- data/lib/active_record/tasks/mysql_database_tasks.rb +5 -5
- data/lib/active_record/tasks/postgresql_database_tasks.rb +5 -7
- data/lib/active_record/tasks/sqlite_database_tasks.rb +2 -8
- data/lib/active_record/test_databases.rb +38 -0
- data/lib/active_record/test_fixtures.rb +224 -0
- data/lib/active_record/timestamp.rb +39 -25
- data/lib/active_record/touch_later.rb +4 -2
- data/lib/active_record/transactions.rb +57 -66
- data/lib/active_record/translation.rb +1 -1
- data/lib/active_record/type.rb +3 -4
- data/lib/active_record/type/adapter_specific_registry.rb +1 -8
- data/lib/active_record/type_caster/connection.rb +15 -14
- data/lib/active_record/type_caster/map.rb +1 -4
- data/lib/active_record/validations/uniqueness.rb +15 -27
- data/lib/arel.rb +51 -0
- data/lib/arel/alias_predication.rb +9 -0
- data/lib/arel/attributes.rb +22 -0
- data/lib/arel/attributes/attribute.rb +37 -0
- data/lib/arel/collectors/bind.rb +24 -0
- data/lib/arel/collectors/composite.rb +31 -0
- data/lib/arel/collectors/plain_string.rb +20 -0
- data/lib/arel/collectors/sql_string.rb +20 -0
- data/lib/arel/collectors/substitute_binds.rb +28 -0
- data/lib/arel/crud.rb +42 -0
- data/lib/arel/delete_manager.rb +18 -0
- data/lib/arel/errors.rb +9 -0
- data/lib/arel/expressions.rb +29 -0
- data/lib/arel/factory_methods.rb +49 -0
- data/lib/arel/insert_manager.rb +49 -0
- data/lib/arel/math.rb +45 -0
- data/lib/arel/nodes.rb +68 -0
- data/lib/arel/nodes/and.rb +32 -0
- data/lib/arel/nodes/ascending.rb +23 -0
- data/lib/arel/nodes/binary.rb +52 -0
- data/lib/arel/nodes/bind_param.rb +36 -0
- data/lib/arel/nodes/case.rb +55 -0
- data/lib/arel/nodes/casted.rb +50 -0
- data/lib/arel/nodes/comment.rb +29 -0
- data/lib/arel/nodes/count.rb +12 -0
- data/lib/arel/nodes/delete_statement.rb +45 -0
- data/lib/arel/nodes/descending.rb +23 -0
- data/lib/arel/nodes/equality.rb +18 -0
- data/lib/arel/nodes/extract.rb +24 -0
- data/lib/arel/nodes/false.rb +16 -0
- data/lib/arel/nodes/full_outer_join.rb +8 -0
- data/lib/arel/nodes/function.rb +44 -0
- data/lib/arel/nodes/grouping.rb +8 -0
- data/lib/arel/nodes/in.rb +8 -0
- data/lib/arel/nodes/infix_operation.rb +80 -0
- data/lib/arel/nodes/inner_join.rb +8 -0
- data/lib/arel/nodes/insert_statement.rb +37 -0
- data/lib/arel/nodes/join_source.rb +20 -0
- data/lib/arel/nodes/matches.rb +18 -0
- data/lib/arel/nodes/named_function.rb +23 -0
- data/lib/arel/nodes/node.rb +50 -0
- data/lib/arel/nodes/node_expression.rb +13 -0
- data/lib/arel/nodes/outer_join.rb +8 -0
- data/lib/arel/nodes/over.rb +15 -0
- data/lib/arel/nodes/regexp.rb +16 -0
- data/lib/arel/nodes/right_outer_join.rb +8 -0
- data/lib/arel/nodes/select_core.rb +67 -0
- data/lib/arel/nodes/select_statement.rb +41 -0
- data/lib/arel/nodes/sql_literal.rb +16 -0
- data/lib/arel/nodes/string_join.rb +11 -0
- data/lib/arel/nodes/table_alias.rb +27 -0
- data/lib/arel/nodes/terminal.rb +16 -0
- data/lib/arel/nodes/true.rb +16 -0
- data/lib/arel/nodes/unary.rb +45 -0
- data/lib/arel/nodes/unary_operation.rb +20 -0
- data/lib/arel/nodes/unqualified_column.rb +22 -0
- data/lib/arel/nodes/update_statement.rb +41 -0
- data/lib/arel/nodes/values_list.rb +9 -0
- data/lib/arel/nodes/window.rb +126 -0
- data/lib/arel/nodes/with.rb +11 -0
- data/lib/arel/order_predications.rb +13 -0
- data/lib/arel/predications.rb +257 -0
- data/lib/arel/select_manager.rb +271 -0
- data/lib/arel/table.rb +110 -0
- data/lib/arel/tree_manager.rb +72 -0
- data/lib/arel/update_manager.rb +34 -0
- data/lib/arel/visitors.rb +20 -0
- data/lib/arel/visitors/depth_first.rb +204 -0
- data/lib/arel/visitors/dot.rb +297 -0
- data/lib/arel/visitors/ibm_db.rb +34 -0
- data/lib/arel/visitors/informix.rb +62 -0
- data/lib/arel/visitors/mssql.rb +157 -0
- data/lib/arel/visitors/mysql.rb +83 -0
- data/lib/arel/visitors/oracle.rb +159 -0
- data/lib/arel/visitors/oracle12.rb +66 -0
- data/lib/arel/visitors/postgresql.rb +110 -0
- data/lib/arel/visitors/sqlite.rb +39 -0
- data/lib/arel/visitors/to_sql.rb +889 -0
- data/lib/arel/visitors/visitor.rb +46 -0
- data/lib/arel/visitors/where_sql.rb +23 -0
- data/lib/arel/window_predications.rb +9 -0
- data/lib/rails/generators/active_record/migration.rb +14 -1
- data/lib/rails/generators/active_record/migration/migration_generator.rb +2 -5
- data/lib/rails/generators/active_record/migration/templates/create_table_migration.rb.tt +1 -1
- data/lib/rails/generators/active_record/migration/templates/migration.rb.tt +4 -2
- data/lib/rails/generators/active_record/model/model_generator.rb +1 -0
- data/lib/rails/generators/active_record/model/templates/model.rb.tt +10 -1
- metadata +108 -26
- data/lib/active_record/collection_cache_key.rb +0 -53
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 97bc72165e9eb1685576780f439be5be8894b7c589cc890d8c6340b8125de0a4
|
4
|
+
data.tar.gz: 74d58cd2f64976ef8faa42a02e94e6d9c9356fce3f0f2c219f7377a09712e7a4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5306d17e736a64c87fc0115299b055c58343df4d18a53d532b09e570d6cc799abf84b4149deef9c03f56563ed23ee563cf57d03fc6c65529e9a6aa0324ca1614
|
7
|
+
data.tar.gz: 6fe8094ad7c0d0433c23691e372417124bddf17659c4bcb64b0bca5af0513d2c9b8599cfe0c244d28649529ab64b99c4a74b638bdf5ab9b4932c276a287d1e78
|
data/CHANGELOG.md
CHANGED
@@ -1,18 +1,8 @@
|
|
1
|
-
## Rails
|
1
|
+
## Rails 6.0.0.rc2 (July 22, 2019) ##
|
2
2
|
|
3
|
-
*
|
4
|
-
|
5
|
-
Prior to the fix, when there was a circular series of `autosave: true`
|
6
|
-
associations, the callback for a `has_many` association was run while
|
7
|
-
another instance of the same callback on the same association hadn't
|
8
|
-
finished running. When control returned to the first instance of the
|
9
|
-
callback, the instance variable had changed, and subsequent associated
|
10
|
-
records weren't saved correctly. Specifically, the ID field for the
|
11
|
-
`belongs_to` corresponding to the `has_many` was `nil`.
|
3
|
+
* Add database_exists? method to connection adapters to check if a database exists.
|
12
4
|
|
13
|
-
|
14
|
-
|
15
|
-
*Larry Reid*
|
5
|
+
*Guilherme Mansur*
|
16
6
|
|
17
7
|
* PostgreSQL: Fix GROUP BY with ORDER BY virtual count attribute.
|
18
8
|
|
@@ -20,958 +10,979 @@
|
|
20
10
|
|
21
11
|
*Ryuta Kamizono*
|
22
12
|
|
23
|
-
* Fix sqlite3 collation parsing when using decimal columns.
|
24
|
-
|
25
|
-
*Martin R. Schuster*
|
26
|
-
|
27
13
|
* Make ActiveRecord `ConnectionPool.connections` method thread-safe.
|
28
14
|
|
29
15
|
Fixes #36465.
|
30
16
|
|
31
17
|
*Jeff Doering*
|
32
18
|
|
33
|
-
*
|
34
|
-
`before_add` and `after_add` callbacks for `has_many :through` associations.
|
35
|
-
|
36
|
-
Fixes #33249.
|
37
|
-
|
38
|
-
*Ryan H. Kerr*
|
39
|
-
|
19
|
+
* Fix sqlite3 collation parsing when using decimal columns.
|
40
20
|
|
41
|
-
|
21
|
+
*Martin R. Schuster*
|
42
22
|
|
43
|
-
* Fix
|
23
|
+
* Fix invalid schema when primary key column has a comment.
|
44
24
|
|
45
|
-
Fixes #
|
25
|
+
Fixes #29966.
|
46
26
|
|
47
|
-
*
|
27
|
+
*Guilherme Goettems Schneider*
|
48
28
|
|
49
|
-
* Fix
|
29
|
+
* Fix table comment also being applied to the primary key column.
|
50
30
|
|
51
|
-
*
|
31
|
+
*Guilherme Goettems Schneider*
|
52
32
|
|
53
|
-
*
|
33
|
+
* Fix merging left_joins to maintain its own `join_type` context.
|
54
34
|
|
55
|
-
Fixes #
|
35
|
+
Fixes #36103.
|
56
36
|
|
57
37
|
*Ryuta Kamizono*
|
58
38
|
|
59
|
-
* Restore an ability that class level `update` without giving ids.
|
60
39
|
|
61
|
-
|
40
|
+
## Rails 6.0.0.rc1 (April 24, 2019) ##
|
62
41
|
|
63
|
-
|
42
|
+
* Add `touch` option to `has_one` association.
|
64
43
|
|
65
|
-
*
|
44
|
+
*Abhay Nikam*
|
66
45
|
|
67
|
-
|
46
|
+
* Deprecate `where.not` working as NOR and will be changed to NAND in Rails 6.1.
|
68
47
|
|
69
|
-
|
48
|
+
```ruby
|
49
|
+
all = [treasures(:diamond), treasures(:sapphire), cars(:honda), treasures(:sapphire)]
|
50
|
+
assert_equal all, PriceEstimate.all.map(&:estimate_of)
|
51
|
+
```
|
70
52
|
|
71
|
-
|
53
|
+
In Rails 6.0:
|
72
54
|
|
73
|
-
|
55
|
+
```ruby
|
56
|
+
sapphire = treasures(:sapphire)
|
57
|
+
|
58
|
+
nor = all.reject { |e|
|
59
|
+
e.estimate_of_type == sapphire.class.polymorphic_name
|
60
|
+
}.reject { |e|
|
61
|
+
e.estimate_of_id == sapphire.id
|
62
|
+
}
|
63
|
+
assert_equal [cars(:honda)], nor
|
64
|
+
|
65
|
+
without_sapphire = PriceEstimate.where.not(
|
66
|
+
estimate_of_type: sapphire.class.polymorphic_name, estimate_of_id: sapphire.id
|
67
|
+
)
|
68
|
+
assert_equal nor, without_sapphire.map(&:estimate_of)
|
69
|
+
```
|
74
70
|
|
75
|
-
|
71
|
+
In Rails 6.1:
|
76
72
|
|
73
|
+
```ruby
|
74
|
+
sapphire = treasures(:sapphire)
|
77
75
|
|
78
|
-
|
76
|
+
nand = all - [sapphire]
|
77
|
+
assert_equal [treasures(:diamond), cars(:honda)], nand
|
79
78
|
|
80
|
-
|
79
|
+
without_sapphire = PriceEstimate.where.not(
|
80
|
+
estimate_of_type: sapphire.class.polymorphic_name, estimate_of_id: sapphire.id
|
81
|
+
)
|
82
|
+
assert_equal nand, without_sapphire.map(&:estimate_of)
|
83
|
+
```
|
81
84
|
|
85
|
+
*Ryuta Kamizono*
|
82
86
|
|
83
|
-
|
87
|
+
* Fix dirty tracking after rollback.
|
84
88
|
|
85
|
-
|
89
|
+
Fixes #15018, #30167, #33868.
|
86
90
|
|
87
91
|
*Ryuta Kamizono*
|
88
92
|
|
89
|
-
*
|
93
|
+
* Add `ActiveRecord::Relation#cache_version` to support recyclable cache keys via
|
94
|
+
the versioned entries in `ActiveSupport::Cache`. This also means that
|
95
|
+
`ActiveRecord::Relation#cache_key` will now return a stable key that does not
|
96
|
+
include the max timestamp or count any more.
|
90
97
|
|
91
|
-
|
92
|
-
|
93
|
-
|
98
|
+
NOTE: This feature is turned off by default, and `cache_key` will still return
|
99
|
+
cache keys with timestamps until you set `ActiveRecord::Base.collection_cache_versioning = true`.
|
100
|
+
That's the setting for all new apps on Rails 6.0+
|
94
101
|
|
95
|
-
|
96
|
-
adapter.
|
102
|
+
*Lachlan Sylvester*
|
97
103
|
|
98
|
-
|
99
|
-
|
100
|
-
* Cached columns_hash fields should be excluded from ResultSet#column_types
|
104
|
+
* Fix dirty tracking for `touch` to track saved changes.
|
101
105
|
|
102
|
-
|
103
|
-
was passing for SQLite and MySQL, but failed for PostgreSQL:
|
106
|
+
Fixes #33429.
|
104
107
|
|
105
|
-
|
106
|
-
class DeveloperName < ActiveRecord::Type::String
|
107
|
-
def deserialize(value)
|
108
|
-
"Developer: #{value}"
|
109
|
-
end
|
110
|
-
end
|
108
|
+
*Ryuta Kamzono*
|
111
109
|
|
112
|
-
|
113
|
-
|
110
|
+
* `change_column_comment` and `change_table_comment` are invertible only if
|
111
|
+
`to` and `from` options are specified.
|
114
112
|
|
115
|
-
|
113
|
+
*Yoshiyuki Kinjo*
|
116
114
|
|
117
|
-
|
118
|
-
end
|
115
|
+
* Don't call commit/rollback callbacks when a record isn't saved.
|
119
116
|
|
120
|
-
|
121
|
-
developer.update_column :name, "name"
|
117
|
+
Fixes #29747.
|
122
118
|
|
123
|
-
|
124
|
-
puts loaded_developer.name # should be "Developer: name" but it's just "name"
|
125
|
-
```
|
119
|
+
*Ryuta Kamizono*
|
126
120
|
|
127
|
-
|
121
|
+
* Fix circular `autosave: true` causes invalid records to be saved.
|
128
122
|
|
129
|
-
|
123
|
+
Prior to the fix, when there was a circular series of `autosave: true`
|
124
|
+
associations, the callback for a `has_many` association was run while
|
125
|
+
another instance of the same callback on the same association hadn't
|
126
|
+
finished running. When control returned to the first instance of the
|
127
|
+
callback, the instance variable had changed, and subsequent associated
|
128
|
+
records weren't saved correctly. Specifically, the ID field for the
|
129
|
+
`belongs_to` corresponding to the `has_many` was `nil`.
|
130
130
|
|
131
|
-
|
131
|
+
Fixes #28080.
|
132
132
|
|
133
|
-
*
|
134
|
-
if the attribute does not exist.
|
133
|
+
*Larry Reid*
|
135
134
|
|
136
|
-
|
135
|
+
* Raise `ArgumentError` for invalid `:limit` and `:precision` like as other options.
|
137
136
|
|
138
|
-
|
137
|
+
Before:
|
139
138
|
|
140
|
-
|
139
|
+
```ruby
|
140
|
+
add_column :items, :attr1, :binary, size: 10 # => ArgumentError
|
141
|
+
add_column :items, :attr2, :decimal, scale: 10 # => ArgumentError
|
142
|
+
add_column :items, :attr3, :integer, limit: 10 # => ActiveRecordError
|
143
|
+
add_column :items, :attr4, :datetime, precision: 10 # => ActiveRecordError
|
144
|
+
```
|
141
145
|
|
142
|
-
|
146
|
+
After:
|
143
147
|
|
144
|
-
|
148
|
+
```ruby
|
149
|
+
add_column :items, :attr1, :binary, size: 10 # => ArgumentError
|
150
|
+
add_column :items, :attr2, :decimal, scale: 10 # => ArgumentError
|
151
|
+
add_column :items, :attr3, :integer, limit: 10 # => ArgumentError
|
152
|
+
add_column :items, :attr4, :datetime, precision: 10 # => ArgumentError
|
153
|
+
```
|
145
154
|
|
146
|
-
*
|
155
|
+
*Ryuta Kamizono*
|
147
156
|
|
148
|
-
|
157
|
+
* Association loading isn't to be affected by scoping consistently
|
158
|
+
whether preloaded / eager loaded or not, with the exception of `unscoped`.
|
149
159
|
|
150
|
-
|
160
|
+
Before:
|
151
161
|
|
152
|
-
|
162
|
+
```ruby
|
163
|
+
Post.where("1=0").scoping do
|
164
|
+
Comment.find(1).post # => nil
|
165
|
+
Comment.preload(:post).find(1).post # => #<Post id: 1, ...>
|
166
|
+
Comment.eager_load(:post).find(1).post # => #<Post id: 1, ...>
|
167
|
+
end
|
168
|
+
```
|
153
169
|
|
154
|
-
|
170
|
+
After:
|
155
171
|
|
156
|
-
|
172
|
+
```ruby
|
173
|
+
Post.where("1=0").scoping do
|
174
|
+
Comment.find(1).post # => #<Post id: 1, ...>
|
175
|
+
Comment.preload(:post).find(1).post # => #<Post id: 1, ...>
|
176
|
+
Comment.eager_load(:post).find(1).post # => #<Post id: 1, ...>
|
177
|
+
end
|
178
|
+
```
|
157
179
|
|
158
|
-
|
180
|
+
Fixes #34638, #35398.
|
159
181
|
|
160
|
-
*
|
182
|
+
*Ryuta Kamizono*
|
161
183
|
|
162
|
-
|
184
|
+
* Add `rails db:prepare` to migrate or setup a database.
|
163
185
|
|
164
|
-
|
186
|
+
Runs `db:migrate` if the database exists or `db:setup` if it doesn't.
|
165
187
|
|
166
|
-
*
|
188
|
+
*Roberto Miranda*
|
167
189
|
|
168
|
-
*
|
190
|
+
* Add `after_save_commit` callback as shortcut for `after_commit :hook, on: [ :create, :update ]`.
|
169
191
|
|
170
|
-
*
|
192
|
+
*DHH*
|
171
193
|
|
172
|
-
*
|
194
|
+
* Assign all attributes before calling `build` to ensure the child record is visible in
|
195
|
+
`before_add` and `after_add` callbacks for `has_many :through` associations.
|
173
196
|
|
174
|
-
|
197
|
+
Fixes #33249.
|
175
198
|
|
176
|
-
*
|
199
|
+
*Ryan H. Kerr*
|
177
200
|
|
178
|
-
|
201
|
+
* Add `ActiveRecord::Relation#extract_associated` for extracting associated records from a relation.
|
179
202
|
|
180
|
-
|
203
|
+
```
|
204
|
+
account.memberships.extract_associated(:user)
|
205
|
+
# => Returns collection of User records
|
206
|
+
```
|
181
207
|
|
182
|
-
*
|
208
|
+
*DHH*
|
183
209
|
|
210
|
+
* Add `ActiveRecord::Relation#annotate` for adding SQL comments to its queries.
|
184
211
|
|
185
|
-
|
212
|
+
For example:
|
186
213
|
|
187
|
-
|
214
|
+
```
|
215
|
+
Post.where(id: 123).annotate("this is a comment").to_sql
|
216
|
+
# SELECT "posts".* FROM "posts" WHERE "posts"."id" = 123 /* this is a comment */
|
217
|
+
```
|
188
218
|
|
219
|
+
This can be useful in instrumentation or other analysis of issued queries.
|
189
220
|
|
190
|
-
|
221
|
+
*Matt Yoho*
|
191
222
|
|
192
|
-
*
|
223
|
+
* Support Optimizer Hints.
|
193
224
|
|
194
|
-
|
225
|
+
In most databases, a way to control the optimizer is by using optimizer hints,
|
226
|
+
which can be specified within individual statements.
|
195
227
|
|
196
|
-
|
228
|
+
Example (for MySQL):
|
197
229
|
|
198
|
-
|
230
|
+
Topic.optimizer_hints("MAX_EXECUTION_TIME(50000)", "NO_INDEX_MERGE(topics)")
|
231
|
+
# SELECT /*+ MAX_EXECUTION_TIME(50000) NO_INDEX_MERGE(topics) */ `topics`.* FROM `topics`
|
199
232
|
|
200
|
-
|
233
|
+
Example (for PostgreSQL with pg_hint_plan):
|
201
234
|
|
202
|
-
|
235
|
+
Topic.optimizer_hints("SeqScan(topics)", "Parallel(topics 8)")
|
236
|
+
# SELECT /*+ SeqScan(topics) Parallel(topics 8) */ "topics".* FROM "topics"
|
203
237
|
|
204
|
-
|
238
|
+
See also:
|
205
239
|
|
206
|
-
*
|
240
|
+
* https://dev.mysql.com/doc/refman/8.0/en/optimizer-hints.html
|
241
|
+
* https://pghintplan.osdn.jp/pg_hint_plan.html
|
242
|
+
* https://docs.oracle.com/en/database/oracle/oracle-database/12.2/tgsql/influencing-the-optimizer.html
|
243
|
+
* https://docs.microsoft.com/en-us/sql/t-sql/queries/hints-transact-sql-query?view=sql-server-2017
|
244
|
+
* https://www.ibm.com/support/knowledgecenter/en/SSEPGG_11.1.0/com.ibm.db2.luw.admin.perf.doc/doc/c0070117.html
|
207
245
|
|
208
246
|
*Ryuta Kamizono*
|
209
247
|
|
210
|
-
* Fix
|
248
|
+
* Fix query attribute method on user-defined attribute to be aware of typecasted value.
|
211
249
|
|
212
|
-
|
250
|
+
For example, the following code no longer return false as casted non-empty string:
|
213
251
|
|
214
|
-
|
252
|
+
```
|
253
|
+
class Post < ActiveRecord::Base
|
254
|
+
attribute :user_defined_text, :text
|
255
|
+
end
|
215
256
|
|
216
|
-
|
257
|
+
Post.new(user_defined_text: "false").user_defined_text? # => true
|
258
|
+
```
|
217
259
|
|
218
|
-
*
|
260
|
+
*Yuji Kamijima*
|
219
261
|
|
220
|
-
*
|
262
|
+
* Quote empty ranges like other empty enumerables.
|
221
263
|
|
222
|
-
|
264
|
+
*Patrick Rebsch*
|
223
265
|
|
224
|
-
|
266
|
+
* Add `insert_all`/`insert_all!`/`upsert_all` methods to `ActiveRecord::Persistence`,
|
267
|
+
allowing bulk inserts akin to the bulk updates provided by `update_all` and
|
268
|
+
bulk deletes by `delete_all`.
|
225
269
|
|
226
|
-
|
270
|
+
Supports skipping or upserting duplicates through the `ON CONFLICT` syntax
|
271
|
+
for PostgreSQL (9.5+) and SQLite (3.24+) and `ON DUPLICATE KEY UPDATE` syntax
|
272
|
+
for MySQL.
|
227
273
|
|
228
|
-
|
274
|
+
*Bob Lail*
|
229
275
|
|
230
|
-
|
276
|
+
* Add `rails db:seed:replant` that truncates tables of each database
|
277
|
+
for current environment and loads the seeds.
|
231
278
|
|
232
|
-
*
|
279
|
+
*bogdanvlviv*, *DHH*
|
233
280
|
|
234
|
-
|
281
|
+
* Add `ActiveRecord::Base.connection.truncate` for SQLite3 adapter.
|
235
282
|
|
236
|
-
*
|
283
|
+
*bogdanvlviv*
|
237
284
|
|
238
|
-
*
|
285
|
+
* Deprecate mismatched collation comparison for uniqueness validator.
|
239
286
|
|
240
|
-
|
287
|
+
Uniqueness validator will no longer enforce case sensitive comparison in Rails 6.1.
|
288
|
+
To continue case sensitive comparison on the case insensitive column,
|
289
|
+
pass `case_sensitive: true` option explicitly to the uniqueness validator.
|
241
290
|
|
242
|
-
*
|
243
|
-
wrongly persists through record.
|
291
|
+
*Ryuta Kamizono*
|
244
292
|
|
245
|
-
|
293
|
+
* Add `reselect` method. This is a short-hand for `unscope(:select).select(fields)`.
|
246
294
|
|
247
|
-
|
295
|
+
Fixes #27340.
|
248
296
|
|
249
|
-
*
|
250
|
-
query cache.
|
297
|
+
*Willian Gustavo Veiga*
|
251
298
|
|
252
|
-
|
299
|
+
* Add negative scopes for all enum values.
|
253
300
|
|
301
|
+
Example:
|
254
302
|
|
255
|
-
|
303
|
+
class Post < ActiveRecord::Base
|
304
|
+
enum status: %i[ drafted active trashed ]
|
305
|
+
end
|
256
306
|
|
257
|
-
|
307
|
+
Post.not_drafted # => where.not(status: :drafted)
|
308
|
+
Post.not_active # => where.not(status: :active)
|
309
|
+
Post.not_trashed # => where.not(status: :trashed)
|
258
310
|
|
259
|
-
*
|
311
|
+
*DHH*
|
260
312
|
|
261
|
-
*
|
313
|
+
* Fix different `count` calculation when using `size` with manual `select` with DISTINCT.
|
262
314
|
|
263
|
-
|
264
|
-
have a specified precision then on assignment the value is rounded to
|
265
|
-
that precision. This behavior is now applied to time columns as well.
|
315
|
+
Fixes #35214.
|
266
316
|
|
267
|
-
|
317
|
+
*Juani Villarejo*
|
268
318
|
|
269
|
-
*Andrew White*
|
270
319
|
|
271
|
-
|
320
|
+
## Rails 6.0.0.beta3 (March 11, 2019) ##
|
272
321
|
|
273
|
-
|
274
|
-
because until #24542 the quoting for time columns didn't remove the date
|
275
|
-
component. To ensure that values are consistent we now normalize the
|
276
|
-
date component to 2001-01-01 on reading and writing.
|
322
|
+
* No changes.
|
277
323
|
|
278
|
-
*Andrew White*
|
279
324
|
|
280
|
-
|
325
|
+
## Rails 6.0.0.beta2 (February 25, 2019) ##
|
281
326
|
|
282
|
-
|
283
|
-
was removed however it only removed it when it was 2001-01-01. Now the
|
284
|
-
date component is removed irrespective of what the date is.
|
327
|
+
* Fix prepared statements caching to be enabled even when query caching is enabled.
|
285
328
|
|
286
|
-
*
|
329
|
+
*Ryuta Kamizono*
|
287
330
|
|
288
|
-
*
|
289
|
-
the parent class was getting deleted when the child was not.
|
331
|
+
* Ensure `update_all` series cares about optimistic locking.
|
290
332
|
|
291
|
-
|
333
|
+
*Ryuta Kamizono*
|
292
334
|
|
293
|
-
|
335
|
+
* Don't allow `where` with non numeric string matches to 0 values.
|
294
336
|
|
295
|
-
*
|
337
|
+
*Ryuta Kamizono*
|
296
338
|
|
297
|
-
|
339
|
+
* Introduce `ActiveRecord::Relation#destroy_by` and `ActiveRecord::Relation#delete_by`.
|
298
340
|
|
299
|
-
|
341
|
+
`destroy_by` allows relation to find all the records matching the condition and perform
|
342
|
+
`destroy_all` on the matched records.
|
300
343
|
|
301
|
-
|
344
|
+
Example:
|
302
345
|
|
303
|
-
|
304
|
-
|
305
|
-
even if `ORDER BY` columns include other table's primary key.
|
346
|
+
Person.destroy_by(name: 'David')
|
347
|
+
Person.destroy_by(name: 'David', rating: 4)
|
306
348
|
|
307
|
-
|
349
|
+
david = Person.find_by(name: 'David')
|
350
|
+
david.posts.destroy_by(id: [1, 2, 3])
|
308
351
|
|
309
|
-
|
352
|
+
`delete_by` allows relation to find all the records matching the condition and perform
|
353
|
+
`delete_all` on the matched records.
|
310
354
|
|
311
|
-
|
355
|
+
Example:
|
312
356
|
|
313
|
-
|
357
|
+
Person.delete_by(name: 'David')
|
358
|
+
Person.delete_by(name: 'David', rating: 4)
|
314
359
|
|
315
|
-
|
360
|
+
david = Person.find_by(name: 'David')
|
361
|
+
david.posts.delete_by(id: [1, 2, 3])
|
316
362
|
|
317
|
-
*
|
363
|
+
*Abhay Nikam*
|
318
364
|
|
319
|
-
|
365
|
+
* Don't allow `where` with invalid value matches to nil values.
|
320
366
|
|
321
|
-
|
322
|
-
Using a `Relation` for performing queries is the prefered API.
|
367
|
+
Fixes #33624.
|
323
368
|
|
324
369
|
*Ryuta Kamizono*
|
325
370
|
|
326
|
-
*
|
371
|
+
* SQLite3: Implement `add_foreign_key` and `remove_foreign_key`.
|
327
372
|
|
328
|
-
|
329
|
-
david_balance = customers(:david).balance
|
330
|
-
Customer.where(balance: [david_balance]).to_sql
|
331
|
-
|
332
|
-
# Before: WHERE `customers`.`balance` = NULL
|
333
|
-
# After : WHERE `customers`.`balance` = 50
|
334
|
-
```
|
373
|
+
*Ryuta Kamizono*
|
335
374
|
|
336
|
-
|
375
|
+
* Deprecate using class level querying methods if the receiver scope
|
376
|
+
regarded as leaked. Use `klass.unscoped` to avoid the leaking scope.
|
337
377
|
|
338
|
-
*
|
378
|
+
*Ryuta Kamizono*
|
339
379
|
|
340
|
-
*
|
380
|
+
* Allow applications to automatically switch connections.
|
341
381
|
|
342
|
-
|
382
|
+
Adds a middleware and configuration options that can be used in your
|
383
|
+
application to automatically switch between the writing and reading
|
384
|
+
database connections.
|
343
385
|
|
344
|
-
|
386
|
+
`GET` and `HEAD` requests will read from the replica unless there was
|
387
|
+
a write in the last 2 seconds, otherwise they will read from the primary.
|
388
|
+
Non-get requests will always write to the primary. The middleware accepts
|
389
|
+
an argument for a Resolver class and a Operations class where you are able
|
390
|
+
to change how the auto-switcher works to be most beneficial for your
|
391
|
+
application.
|
345
392
|
|
346
|
-
|
393
|
+
To use the middleware in your application you can use the following
|
394
|
+
configuration options:
|
347
395
|
|
348
|
-
|
396
|
+
```
|
397
|
+
config.active_record.database_selector = { delay: 2.seconds }
|
398
|
+
config.active_record.database_resolver = ActiveRecord::Middleware::DatabaseSelector::Resolver
|
399
|
+
config.active_record.database_resolver_context = ActiveRecord::Middleware::DatabaseSelector::Resolver::Session
|
400
|
+
```
|
349
401
|
|
350
|
-
|
402
|
+
To change the database selection strategy, pass a custom class to the
|
403
|
+
configuration options:
|
351
404
|
|
352
|
-
|
405
|
+
```
|
406
|
+
config.active_record.database_selector = { delay: 10.seconds }
|
407
|
+
config.active_record.database_resolver = MyResolver
|
408
|
+
config.active_record.database_resolver_context = MyResolver::MyCookies
|
409
|
+
```
|
353
410
|
|
354
|
-
*
|
411
|
+
*Eileen M. Uchitelle*
|
355
412
|
|
356
|
-
*
|
413
|
+
* MySQL: Support `:size` option to change text and blob size.
|
357
414
|
|
358
|
-
*
|
415
|
+
*Ryuta Kamizono*
|
359
416
|
|
360
|
-
*
|
417
|
+
* Make `t.timestamps` with precision by default.
|
361
418
|
|
362
419
|
*Ryuta Kamizono*
|
363
420
|
|
364
|
-
* Take into account association conditions when deleting through records.
|
365
421
|
|
366
|
-
|
422
|
+
## Rails 6.0.0.beta1 (January 18, 2019) ##
|
367
423
|
|
368
|
-
|
424
|
+
* Remove deprecated `#set_state` from the transaction object.
|
369
425
|
|
370
|
-
*
|
426
|
+
*Rafael Mendonça França*
|
371
427
|
|
372
|
-
|
428
|
+
* Remove deprecated `#supports_statement_cache?` from the database adapters.
|
373
429
|
|
374
|
-
|
375
|
-
belongs_to :author
|
376
|
-
has_many :books, through: :author
|
377
|
-
has_many :subscriptions, through: :books
|
378
|
-
end
|
430
|
+
*Rafael Mendonça França*
|
379
431
|
|
380
|
-
|
381
|
-
has_one :post
|
382
|
-
has_many :books
|
383
|
-
has_many :subscriptions, through: :books
|
384
|
-
end
|
432
|
+
* Remove deprecated `#insert_fixtures` from the database adapters.
|
385
433
|
|
386
|
-
|
387
|
-
belongs_to :author
|
388
|
-
has_many :subscriptions
|
389
|
-
end
|
434
|
+
*Rafael Mendonça França*
|
390
435
|
|
391
|
-
|
392
|
-
belongs_to :book
|
393
|
-
end
|
436
|
+
* Remove deprecated `ActiveRecord::ConnectionAdapters::SQLite3Adapter#valid_alter_table_type?`.
|
394
437
|
|
395
|
-
|
438
|
+
*Rafael Mendonça França*
|
396
439
|
|
397
|
-
|
440
|
+
* Do not allow passing the column name to `sum` when a block is passed.
|
398
441
|
|
399
|
-
|
442
|
+
*Rafael Mendonça França*
|
400
443
|
|
401
|
-
|
402
|
-
just like it would if `post` were persisted.
|
444
|
+
* Do not allow passing the column name to `count` when a block is passed.
|
403
445
|
|
404
|
-
|
446
|
+
*Rafael Mendonça França*
|
405
447
|
|
406
|
-
|
448
|
+
* Remove delegation of missing methods in a relation to arel.
|
407
449
|
|
408
|
-
*
|
409
|
-
The `first(n)` finder now respects the `limit()`, making it consistent
|
410
|
-
with `relation.to_a.first(n)`, and also with the behavior of `last(n)`.
|
450
|
+
*Rafael Mendonça França*
|
411
451
|
|
412
|
-
|
452
|
+
* Remove delegation of missing methods in a relation to private methods of the class.
|
413
453
|
|
414
|
-
*
|
454
|
+
*Rafael Mendonça França*
|
415
455
|
|
416
|
-
*
|
417
|
-
SQL queries for association counting.
|
456
|
+
* Deprecate `config.activerecord.sqlite3.represent_boolean_as_integer`.
|
418
457
|
|
419
|
-
*
|
458
|
+
*Rafael Mendonça França*
|
420
459
|
|
421
|
-
*
|
460
|
+
* Change `SQLite3Adapter` to always represent boolean values as integers.
|
422
461
|
|
423
|
-
*
|
462
|
+
*Rafael Mendonça França*
|
424
463
|
|
425
|
-
*
|
464
|
+
* Remove ability to specify a timestamp name for `#cache_key`.
|
426
465
|
|
427
|
-
*
|
466
|
+
*Rafael Mendonça França*
|
428
467
|
|
429
|
-
*
|
468
|
+
* Remove deprecated `ActiveRecord::Migrator.migrations_path=`.
|
430
469
|
|
431
|
-
*
|
470
|
+
*Rafael Mendonça França*
|
432
471
|
|
433
|
-
*
|
434
|
-
information.
|
472
|
+
* Remove deprecated `expand_hash_conditions_for_aggregates`.
|
435
473
|
|
436
|
-
*
|
474
|
+
*Rafael Mendonça França*
|
437
475
|
|
438
|
-
*
|
476
|
+
* Set polymorphic type column to NULL on `dependent: :nullify` strategy.
|
439
477
|
|
440
|
-
|
441
|
-
of database queries in the log to facilitate N+1 query resolution
|
442
|
-
and other debugging.
|
478
|
+
On polymorphic associations both the foreign key and the foreign type columns will be set to NULL.
|
443
479
|
|
444
|
-
|
445
|
-
recommended for use in the production environment since it relies
|
446
|
-
on Ruby's `Kernel#caller_locations` which is fairly slow.
|
480
|
+
*Laerti Papa*
|
447
481
|
|
448
|
-
|
482
|
+
* Allow permitted instance of `ActionController::Parameters` as argument of `ActiveRecord::Relation#exists?`.
|
449
483
|
|
450
|
-
*
|
484
|
+
*Gannon McGibbon*
|
451
485
|
|
452
|
-
|
453
|
-
# create_table :posts do |t|
|
454
|
-
# t.integer :comments_count, default: 0
|
455
|
-
# t.integer :lock_version
|
456
|
-
# t.timestamps
|
457
|
-
# end
|
458
|
-
class Post < ApplicationRecord
|
459
|
-
end
|
486
|
+
* Add support for endless ranges introduces in Ruby 2.6.
|
460
487
|
|
461
|
-
|
462
|
-
# t.belongs_to :post
|
463
|
-
# end
|
464
|
-
class Comment < ApplicationRecord
|
465
|
-
belongs_to :post, touch: true, counter_cache: true
|
466
|
-
end
|
467
|
-
```
|
488
|
+
*Greg Navis*
|
468
489
|
|
469
|
-
|
470
|
-
```
|
471
|
-
post = Post.create!
|
472
|
-
# => begin transaction
|
473
|
-
INSERT INTO "posts" ("created_at", "updated_at", "lock_version")
|
474
|
-
VALUES ("2017-12-11 21:27:11.387397", "2017-12-11 21:27:11.387397", 0)
|
475
|
-
commit transaction
|
490
|
+
* Deprecate passing `migrations_paths` to `connection.assume_migrated_upto_version`.
|
476
491
|
|
477
|
-
|
478
|
-
# => begin transaction
|
479
|
-
INSERT INTO "comments" ("post_id") VALUES (1)
|
492
|
+
*Ryuta Kamizono*
|
480
493
|
|
481
|
-
|
482
|
-
"lock_version" = COALESCE("lock_version", 0) + 1 WHERE "posts"."id" = 1
|
494
|
+
* MySQL: `ROW_FORMAT=DYNAMIC` create table option by default.
|
483
495
|
|
484
|
-
|
485
|
-
|
486
|
-
|
487
|
-
# => ActiveRecord::StaleObjectError: Attempted to touch a stale object: Post.
|
496
|
+
Since MySQL 5.7.9, the `innodb_default_row_format` option defines the default row
|
497
|
+
format for InnoDB tables. The default setting is `DYNAMIC`.
|
498
|
+
The row format is required for indexing on `varchar(255)` with `utf8mb4` columns.
|
488
499
|
|
489
|
-
|
490
|
-
# => begin transaction
|
491
|
-
DELETE FROM "comments" WHERE "comments"."id" = 1
|
500
|
+
*Ryuta Kamizono*
|
492
501
|
|
493
|
-
|
494
|
-
"lock_version" = COALESCE("lock_version", 0) + 1 WHERE "posts"."id" = 1
|
502
|
+
* Fix join table column quoting with SQLite.
|
495
503
|
|
496
|
-
|
497
|
-
"lock_version" = 1 WHERE "posts"."id" = 1 AND "posts"."lock_version" = 0
|
498
|
-
rollback transaction
|
499
|
-
# => ActiveRecord::StaleObjectError: Attempted to touch a stale object: Post.
|
500
|
-
```
|
504
|
+
*Gannon McGibbon*
|
501
505
|
|
502
|
-
|
503
|
-
```
|
504
|
-
post = Post.create!
|
505
|
-
# => begin transaction
|
506
|
-
INSERT INTO "posts" ("created_at", "updated_at", "lock_version")
|
507
|
-
VALUES ("2017-12-11 21:27:11.387397", "2017-12-11 21:27:11.387397", 0)
|
508
|
-
commit transaction
|
506
|
+
* Allow disabling scopes generated by `ActiveRecord.enum`.
|
509
507
|
|
510
|
-
|
511
|
-
# => begin transaction
|
512
|
-
INSERT INTO "comments" ("post_id") VALUES (1)
|
508
|
+
*Alfred Dominic*
|
513
509
|
|
514
|
-
|
515
|
-
"lock_version" = COALESCE("lock_version", 0) + 1,
|
516
|
-
"updated_at" = '2017-12-11 21:37:09.802642' WHERE "posts"."id" = 1
|
517
|
-
commit transaction
|
510
|
+
* Ensure that `delete_all` on collection proxy returns affected count.
|
518
511
|
|
519
|
-
|
520
|
-
# => begin transaction
|
521
|
-
DELETE FROM "comments" WHERE "comments"."id" = 1
|
512
|
+
*Ryuta Kamizono*
|
522
513
|
|
523
|
-
|
524
|
-
"lock_version" = COALESCE("lock_version", 0) + 1,
|
525
|
-
"updated_at" = '2017-12-11 21:39:02.685520' WHERE "posts"."id" = 1
|
526
|
-
commit transaction
|
527
|
-
```
|
514
|
+
* Reset scope after delete on collection association to clear stale offsets of removed records.
|
528
515
|
|
529
|
-
|
516
|
+
*Gannon McGibbon*
|
530
517
|
|
531
|
-
|
518
|
+
* Add the ability to prevent writes to a database for the duration of a block.
|
532
519
|
|
533
|
-
|
520
|
+
Allows the application to prevent writes to a database. This can be useful when
|
521
|
+
you're building out multiple databases and want to make sure you're not sending
|
522
|
+
writes when you want a read.
|
534
523
|
|
535
|
-
|
524
|
+
If `while_preventing_writes` is called and the query is considered a write
|
525
|
+
query the database will raise an exception regardless of whether the database
|
526
|
+
user is able to write.
|
536
527
|
|
537
|
-
|
528
|
+
This is not meant to be a catch-all for write queries but rather a way to enforce
|
529
|
+
read-only queries without opening a second connection. One purpose of this is to
|
530
|
+
catch accidental writes, not all writes.
|
538
531
|
|
539
|
-
*
|
532
|
+
*Eileen M. Uchitelle*
|
540
533
|
|
541
|
-
*
|
534
|
+
* Allow aliased attributes to be used in `#update_columns` and `#update`.
|
542
535
|
|
543
|
-
|
536
|
+
*Gannon McGibbon*
|
544
537
|
|
545
|
-
|
538
|
+
* Allow spaces in postgres table names.
|
546
539
|
|
547
|
-
|
548
|
-
when canceling statement due to user request.
|
540
|
+
Fixes issue where "user post" is misinterpreted as "\"user\".\"post\"" when quoting table names with the postgres adapter.
|
549
541
|
|
550
|
-
*
|
542
|
+
*Gannon McGibbon*
|
551
543
|
|
552
|
-
*
|
553
|
-
migrating up, e.g. populating a new column.
|
544
|
+
* Cached `columns_hash` fields should be excluded from `ResultSet#column_types`.
|
554
545
|
|
555
|
-
|
546
|
+
PR #34528 addresses the inconsistent behaviour when attribute is defined for an ignored column. The following test
|
547
|
+
was passing for SQLite and MySQL, but failed for PostgreSQL:
|
556
548
|
|
557
|
-
|
558
|
-
|
549
|
+
```ruby
|
550
|
+
class DeveloperName < ActiveRecord::Type::String
|
551
|
+
def deserialize(value)
|
552
|
+
"Developer: #{value}"
|
553
|
+
end
|
554
|
+
end
|
559
555
|
|
560
|
-
|
561
|
-
|
562
|
-
Article.order("LENGTH(title)")
|
563
|
-
```
|
556
|
+
class AttributedDeveloper < ActiveRecord::Base
|
557
|
+
self.table_name = "developers"
|
564
558
|
|
565
|
-
|
566
|
-
```
|
567
|
-
Article.order(Arel.sql("LENGTH(title)"))
|
568
|
-
```
|
559
|
+
attribute :name, DeveloperName.new
|
569
560
|
|
570
|
-
|
571
|
-
|
572
|
-
mistaken belief that only column names will be accepted.
|
561
|
+
self.ignored_columns += ["name"]
|
562
|
+
end
|
573
563
|
|
574
|
-
|
575
|
-
|
576
|
-
can opt in to the future behavior by setting `allow_unsafe_raw_sql`
|
577
|
-
to `:disabled`.
|
564
|
+
developer = AttributedDeveloper.create
|
565
|
+
developer.update_column :name, "name"
|
578
566
|
|
579
|
-
|
580
|
-
|
581
|
-
```
|
582
|
-
Article.order("title DESC")
|
567
|
+
loaded_developer = AttributedDeveloper.where(id: developer.id).select("*").first
|
568
|
+
puts loaded_developer.name # should be "Developer: name" but it's just "name"
|
583
569
|
```
|
584
570
|
|
585
|
-
*
|
586
|
-
|
587
|
-
* `update_all` will now pass its values to `Type#cast` before passing them to
|
588
|
-
`Type#serialize`. This means that `update_all(foo: 'true')` will properly
|
589
|
-
persist a boolean.
|
590
|
-
|
591
|
-
*Sean Griffin*
|
592
|
-
|
593
|
-
* Add new error class `StatementTimeout` which will be raised
|
594
|
-
when statement timeout exceeded.
|
595
|
-
|
596
|
-
*Ryuta Kamizono*
|
597
|
-
|
598
|
-
* Fix `bin/rails db:migrate` with specified `VERSION`.
|
599
|
-
`bin/rails db:migrate` with empty VERSION behaves as without `VERSION`.
|
600
|
-
Check a format of `VERSION`: Allow a migration version number
|
601
|
-
or name of a migration file. Raise error if format of `VERSION` is invalid.
|
602
|
-
Raise error if target migration doesn't exist.
|
571
|
+
*Dmitry Tsepelev*
|
603
572
|
|
604
|
-
|
573
|
+
* Make the implicit order column configurable.
|
605
574
|
|
606
|
-
|
607
|
-
|
575
|
+
When calling ordered finder methods such as `first` or `last` without an
|
576
|
+
explicit order clause, ActiveRecord sorts records by primary key. This can
|
577
|
+
result in unpredictable and surprising behaviour when the primary key is
|
578
|
+
not an auto-incrementing integer, for example when it's a UUID. This change
|
579
|
+
makes it possible to override the column used for implicit ordering such
|
580
|
+
that `first` and `last` will return more predictable results.
|
608
581
|
|
609
|
-
|
582
|
+
Example:
|
610
583
|
|
611
|
-
|
584
|
+
class Project < ActiveRecord::Base
|
585
|
+
self.implicit_order_column = "created_at"
|
586
|
+
end
|
612
587
|
|
613
|
-
*
|
588
|
+
*Tekin Suleyman*
|
614
589
|
|
615
|
-
|
590
|
+
* Bump minimum PostgreSQL version to 9.3.
|
616
591
|
|
617
|
-
*
|
592
|
+
*Yasuo Honda*
|
618
593
|
|
619
|
-
|
620
|
-
|
621
|
-
* Remove deprecated configuration `.error_on_ignored_order_or_limit`.
|
594
|
+
* Values of enum are frozen, raising an error when attempting to modify them.
|
622
595
|
|
623
|
-
*
|
596
|
+
*Emmanuel Byrd*
|
624
597
|
|
625
|
-
*
|
598
|
+
* Move `ActiveRecord::StatementInvalid` SQL to error property and include binds as separate error property.
|
626
599
|
|
627
|
-
|
600
|
+
`ActiveRecord::ConnectionAdapters::AbstractAdapter#translate_exception_class` now requires `binds` to be passed as the last argument.
|
628
601
|
|
629
|
-
|
602
|
+
`ActiveRecord::ConnectionAdapters::AbstractAdapter#translate_exception` now requires `message`, `sql`, and `binds` to be passed as keyword arguments.
|
630
603
|
|
631
|
-
|
604
|
+
Subclasses of `ActiveRecord::StatementInvalid` must now provide `sql:` and `binds:` arguments to `super`.
|
632
605
|
|
633
|
-
|
606
|
+
Example:
|
634
607
|
|
635
|
-
|
608
|
+
```
|
609
|
+
class MySubclassedError < ActiveRecord::StatementInvalid
|
610
|
+
def initialize(message, sql:, binds:)
|
611
|
+
super(message, sql: sql, binds: binds)
|
612
|
+
end
|
613
|
+
end
|
614
|
+
```
|
636
615
|
|
637
|
-
*
|
616
|
+
*Gannon McGibbon*
|
638
617
|
|
639
|
-
|
618
|
+
* Add an `:if_not_exists` option to `create_table`.
|
640
619
|
|
641
|
-
|
620
|
+
Example:
|
642
621
|
|
643
|
-
|
622
|
+
create_table :posts, if_not_exists: true do |t|
|
623
|
+
t.string :title
|
624
|
+
end
|
644
625
|
|
645
|
-
|
626
|
+
That would execute:
|
646
627
|
|
647
|
-
|
628
|
+
CREATE TABLE IF NOT EXISTS posts (
|
629
|
+
...
|
630
|
+
)
|
648
631
|
|
649
|
-
|
632
|
+
If the table already exists, `if_not_exists: false` (the default) raises an
|
633
|
+
exception whereas `if_not_exists: true` does nothing.
|
650
634
|
|
651
|
-
*
|
635
|
+
*fatkodima*, *Stefan Kanev*
|
652
636
|
|
653
|
-
*
|
637
|
+
* Defining an Enum as a Hash with blank key, or as an Array with a blank value, now raises an `ArgumentError`.
|
654
638
|
|
655
|
-
*
|
639
|
+
*Christophe Maximin*
|
656
640
|
|
657
|
-
*
|
641
|
+
* Adds support for multiple databases to `rails db:schema:cache:dump` and `rails db:schema:cache:clear`.
|
658
642
|
|
659
|
-
*
|
643
|
+
*Gannon McGibbon*
|
660
644
|
|
661
|
-
*
|
645
|
+
* `update_columns` now correctly raises `ActiveModel::MissingAttributeError`
|
646
|
+
if the attribute does not exist.
|
662
647
|
|
663
|
-
*
|
648
|
+
*Sean Griffin*
|
664
649
|
|
665
|
-
*
|
666
|
-
ar_internal_metadata's data for a test database.
|
650
|
+
* Add support for hash and URL configs in database hash of `ActiveRecord::Base.connected_to`.
|
667
651
|
|
668
|
-
|
669
|
-
|
670
|
-
|
671
|
-
|
672
|
-
key|value|created_at|updated_at
|
673
|
-
environment|development|2017-09-11 23:14:10.815679|2017-09-11 23:14:10.815679
|
674
|
-
```
|
652
|
+
````
|
653
|
+
User.connected_to(database: { writing: "postgres://foo" }) do
|
654
|
+
User.create!(name: "Gannon")
|
655
|
+
end
|
675
656
|
|
676
|
-
|
677
|
-
|
678
|
-
|
679
|
-
|
680
|
-
|
681
|
-
environment|test|2017-09-11 23:14:10.815679|2017-09-11 23:14:10.815679
|
682
|
-
```
|
657
|
+
config = { "adapter" => "sqlite3", "database" => "db/readonly.sqlite3" }
|
658
|
+
User.connected_to(database: { reading: config }) do
|
659
|
+
User.count
|
660
|
+
end
|
661
|
+
````
|
683
662
|
|
684
|
-
|
663
|
+
*Gannon McGibbon*
|
685
664
|
|
686
|
-
|
665
|
+
* Support default expression for MySQL.
|
687
666
|
|
688
|
-
|
667
|
+
MySQL 8.0.13 and higher supports default value to be a function or expression.
|
689
668
|
|
690
|
-
|
669
|
+
https://dev.mysql.com/doc/refman/8.0/en/create-table.html
|
691
670
|
|
692
671
|
*Ryuta Kamizono*
|
693
672
|
|
694
|
-
*
|
695
|
-
|
696
|
-
Fixes #30894.
|
697
|
-
|
698
|
-
*Ryuta Kamizono*
|
673
|
+
* Support expression indexes for MySQL.
|
699
674
|
|
700
|
-
|
675
|
+
MySQL 8.0.13 and higher supports functional key parts that index
|
676
|
+
expression values rather than column or column prefix values.
|
701
677
|
|
702
|
-
|
678
|
+
https://dev.mysql.com/doc/refman/8.0/en/create-index.html
|
703
679
|
|
704
680
|
*Ryuta Kamizono*
|
705
681
|
|
706
|
-
*
|
707
|
-
|
708
|
-
PostgreSQL 9.1+ introduced range types, and Rails added support for using
|
709
|
-
this datatype in Active Record. However, the serialization of
|
710
|
-
`PostgreSQL::OID::Range` was incomplete, because it did not properly
|
711
|
-
cast the bounds that make up the range. This led to subseconds being
|
712
|
-
dropped in SQL commands:
|
682
|
+
* Fix collection cache key with limit and custom select to avoid ambiguous timestamp column error.
|
713
683
|
|
714
|
-
|
684
|
+
Fixes #33056.
|
715
685
|
|
716
|
-
|
717
|
-
# => "[2010-01-01 13:30:00 UTC,2011-02-02 19:30:00 UTC)"
|
686
|
+
*Federico Martinez*
|
718
687
|
|
719
|
-
|
688
|
+
* Add basic API for connection switching to support multiple databases.
|
720
689
|
|
721
|
-
|
722
|
-
# => "[2010-01-01 13:30:00.670277,2011-02-02 19:30:00.745125)"
|
690
|
+
1) Adds a `connects_to` method for models to connect to multiple databases. Example:
|
723
691
|
|
724
|
-
|
692
|
+
```
|
693
|
+
class AnimalsModel < ApplicationRecord
|
694
|
+
self.abstract_class = true
|
725
695
|
|
726
|
-
|
727
|
-
|
696
|
+
connects_to database: { writing: :animals_primary, reading: :animals_replica }
|
697
|
+
end
|
728
698
|
|
729
|
-
|
699
|
+
class Dog < AnimalsModel
|
700
|
+
# connected to both the animals_primary db for writing and the animals_replica for reading
|
701
|
+
end
|
702
|
+
```
|
730
703
|
|
731
|
-
|
704
|
+
2) Adds a `connected_to` block method for switching connection roles or connecting to
|
705
|
+
a database that the model didn't connect to. Connecting to the database in this block is
|
706
|
+
useful when you have another defined connection, for example `slow_replica` that you don't
|
707
|
+
want to connect to by default but need in the console, or a specific code block.
|
732
708
|
|
733
|
-
|
709
|
+
```
|
710
|
+
ActiveRecord::Base.connected_to(role: :reading) do
|
711
|
+
Dog.first # finds dog from replica connected to AnimalsBase
|
712
|
+
Book.first # doesn't have a reading connection, will raise an error
|
713
|
+
end
|
714
|
+
```
|
734
715
|
|
735
|
-
|
716
|
+
```
|
717
|
+
ActiveRecord::Base.connected_to(database: :slow_replica) do
|
718
|
+
SlowReplicaModel.first # if the db config has a slow_replica configuration this will be used to do the lookup, otherwise this will throw an exception
|
719
|
+
end
|
720
|
+
```
|
736
721
|
|
737
|
-
*
|
738
|
-
more descriptive.
|
722
|
+
*Eileen M. Uchitelle*
|
739
723
|
|
740
|
-
|
724
|
+
* Enum raises on invalid definition values
|
741
725
|
|
742
|
-
|
726
|
+
When defining a Hash enum it can be easy to use `[]` instead of `{}`. This
|
727
|
+
commit checks that only valid definition values are provided, those can
|
728
|
+
be a Hash, an array of Symbols or an array of Strings. Otherwise it
|
729
|
+
raises an `ArgumentError`.
|
743
730
|
|
744
|
-
|
745
|
-
when lock wait timeout exceeded.
|
731
|
+
Fixes #33961
|
746
732
|
|
747
|
-
*
|
733
|
+
*Alberto Almagro*
|
748
734
|
|
749
|
-
*
|
735
|
+
* Reloading associations now clears the Query Cache like `Persistence#reload` does.
|
750
736
|
|
751
|
-
|
737
|
+
```
|
738
|
+
class Post < ActiveRecord::Base
|
739
|
+
has_one :category
|
740
|
+
belongs_to :author
|
741
|
+
has_many :comments
|
742
|
+
end
|
752
743
|
|
753
|
-
|
744
|
+
# Each of the following will now clear the query cache.
|
745
|
+
post.reload_category
|
746
|
+
post.reload_author
|
747
|
+
post.comments.reload
|
748
|
+
```
|
754
749
|
|
755
|
-
*
|
750
|
+
*Christophe Maximin*
|
756
751
|
|
757
|
-
*
|
752
|
+
* Added `index` option for `change_table` migration helpers.
|
753
|
+
With this change you can create indexes while adding new
|
754
|
+
columns into the existing tables.
|
758
755
|
|
759
|
-
|
756
|
+
Example:
|
760
757
|
|
761
|
-
|
758
|
+
change_table(:languages) do |t|
|
759
|
+
t.string :country_code, index: true
|
760
|
+
end
|
762
761
|
|
763
|
-
*
|
762
|
+
*Mehmet Emin İNAÇ*
|
764
763
|
|
765
|
-
|
764
|
+
* Fix `transaction` reverting for migrations.
|
766
765
|
|
767
|
-
|
766
|
+
Before: Commands inside a `transaction` in a reverted migration ran uninverted.
|
767
|
+
Now: This change fixes that by reverting commands inside `transaction` block.
|
768
768
|
|
769
|
-
*
|
769
|
+
*fatkodima*, *David Verhasselt*
|
770
770
|
|
771
|
-
*
|
772
|
-
`references` only, as `references` can be implicitly called by `where`.
|
771
|
+
* Raise an error instead of scanning the filesystem root when `fixture_path` is blank.
|
773
772
|
|
774
|
-
|
773
|
+
*Gannon McGibbon*, *Max Albrecht*
|
775
774
|
|
776
|
-
|
775
|
+
* Allow `ActiveRecord::Base.configurations=` to be set with a symbolized hash.
|
777
776
|
|
778
|
-
*
|
779
|
-
need to generate it, it can be created with `rails g application_record`.
|
777
|
+
*Gannon McGibbon*
|
780
778
|
|
781
|
-
|
779
|
+
* Don't update counter cache unless the record is actually saved.
|
782
780
|
|
783
|
-
|
781
|
+
Fixes #31493, #33113, #33117.
|
784
782
|
|
785
783
|
*Ryuta Kamizono*
|
786
784
|
|
787
|
-
*
|
788
|
-
`destroyed_by_association` will now be set to the reflection, matching the
|
789
|
-
behaviour of `has_many` associations.
|
790
|
-
|
791
|
-
*Lisa Ugray*
|
785
|
+
* Deprecate `ActiveRecord::Result#to_hash` in favor of `ActiveRecord::Result#to_a`.
|
792
786
|
|
793
|
-
*
|
787
|
+
*Gannon McGibbon*, *Kevin Cheng*
|
794
788
|
|
795
|
-
|
796
|
-
bind values used by the `or` instead. (possibly other cases too)
|
789
|
+
* SQLite3 adapter supports expression indexes.
|
797
790
|
|
798
791
|
```
|
799
|
-
|
800
|
-
|
801
|
-
|
802
|
-
|
803
|
-
|
792
|
+
create_table :users do |t|
|
793
|
+
t.string :email
|
794
|
+
end
|
795
|
+
|
796
|
+
add_index :users, 'lower(email)', name: 'index_users_on_email', unique: true
|
804
797
|
```
|
805
798
|
|
806
|
-
*
|
799
|
+
*Gray Kemmey*
|
807
800
|
|
808
|
-
*
|
809
|
-
post-type-cast value for rendering in single-field form inputs.
|
801
|
+
* Allow subclasses to redefine autosave callbacks for associated records.
|
810
802
|
|
811
|
-
|
803
|
+
Fixes #33305.
|
812
804
|
|
813
|
-
*
|
814
|
-
`current_scope`, with the exception of `unscoped`.
|
805
|
+
*Andrey Subbota*
|
815
806
|
|
816
|
-
|
807
|
+
* Bump minimum MySQL version to 5.5.8.
|
817
808
|
|
818
|
-
*
|
809
|
+
*Yasuo Honda*
|
819
810
|
|
820
|
-
*
|
811
|
+
* Use MySQL utf8mb4 character set by default.
|
821
812
|
|
822
|
-
|
823
|
-
|
813
|
+
`utf8mb4` character set with 4-Byte encoding supports supplementary characters including emoji.
|
814
|
+
The previous default 3-Byte encoding character set `utf8` is not enough to support them.
|
824
815
|
|
825
|
-
|
826
|
-
for SQLite databases, so it's implemented behind a configuration flag
|
827
|
-
whose default false value is deprecated.
|
816
|
+
*Yasuo Honda*
|
828
817
|
|
829
|
-
|
818
|
+
* Fix duplicated record creation when using nested attributes with `create_with`.
|
830
819
|
|
831
|
-
*
|
832
|
-
`in_batches`).
|
820
|
+
*Darwin Wu*
|
833
821
|
|
834
|
-
|
835
|
-
|
822
|
+
* Configuration item `config.filter_parameters` could also filter out
|
823
|
+
sensitive values of database columns when call `#inspect`.
|
824
|
+
We also added `ActiveRecord::Base::filter_attributes`/`=` in order to
|
825
|
+
specify sensitive attributes to specific model.
|
836
826
|
|
837
|
-
|
827
|
+
```
|
828
|
+
Rails.application.config.filter_parameters += [:credit_card_number, /phone/]
|
829
|
+
Account.last.inspect # => #<Account id: 123, name: "DHH", credit_card_number: [FILTERED], telephone_number: [FILTERED] ...>
|
830
|
+
SecureAccount.filter_attributes += [:name]
|
831
|
+
SecureAccount.last.inspect # => #<SecureAccount id: 42, name: [FILTERED], credit_card_number: [FILTERED] ...>
|
832
|
+
```
|
838
833
|
|
839
|
-
*
|
840
|
-
`ActiveRecord::StatementInvalid` exceptions.
|
834
|
+
*Zhang Kang*, *Yoshiyuki Kinjo*
|
841
835
|
|
842
|
-
|
836
|
+
* Deprecate `column_name_length`, `table_name_length`, `columns_per_table`,
|
837
|
+
`indexes_per_table`, `columns_per_multicolumn_index`, `sql_query_length`,
|
838
|
+
and `joins_per_query` methods in `DatabaseLimits`.
|
843
839
|
|
844
|
-
*
|
840
|
+
*Ryuta Kamizono*
|
845
841
|
|
846
|
-
|
842
|
+
* `ActiveRecord::Base.configurations` now returns an object.
|
847
843
|
|
848
|
-
|
844
|
+
`ActiveRecord::Base.configurations` used to return a hash, but this
|
845
|
+
is an inflexible data model. In order to improve multiple-database
|
846
|
+
handling in Rails, we've changed this to return an object. Some methods
|
847
|
+
are provided to make the object behave hash-like in order to ease the
|
848
|
+
transition process. Since most applications don't manipulate the hash
|
849
|
+
we've decided to add backwards-compatible functionality that will throw
|
850
|
+
a deprecation warning if used, however calling `ActiveRecord::Base.configurations`
|
851
|
+
will use the new version internally and externally.
|
849
852
|
|
850
|
-
|
853
|
+
For example, the following `database.yml`:
|
851
854
|
|
852
|
-
|
853
|
-
|
855
|
+
```
|
856
|
+
development:
|
857
|
+
adapter: sqlite3
|
858
|
+
database: db/development.sqlite3
|
859
|
+
```
|
854
860
|
|
855
|
-
|
856
|
-
parent transaction is rolledback. This will correctly mark records from the inner transaction as not persisted.
|
861
|
+
Used to become a hash:
|
857
862
|
|
858
|
-
|
863
|
+
```
|
864
|
+
{ "development" => { "adapter" => "sqlite3", "database" => "db/development.sqlite3" } }
|
865
|
+
```
|
859
866
|
|
860
|
-
|
867
|
+
Is now converted into the following object:
|
861
868
|
|
862
|
-
|
863
|
-
|
864
|
-
|
869
|
+
```
|
870
|
+
#<ActiveRecord::DatabaseConfigurations:0x00007fd1acbdf800 @configurations=[
|
871
|
+
#<ActiveRecord::DatabaseConfigurations::HashConfig:0x00007fd1acbded10 @env_name="development",
|
872
|
+
@spec_name="primary", @config={"adapter"=>"sqlite3", "database"=>"db/development.sqlite3"}>
|
873
|
+
]
|
874
|
+
```
|
865
875
|
|
866
|
-
|
876
|
+
Iterating over the database configurations has also changed. Instead of
|
877
|
+
calling hash methods on the `configurations` hash directly, a new method `configs_for` has
|
878
|
+
been provided that allows you to select the correct configuration. `env_name` and
|
879
|
+
`spec_name` arguments are optional. For example, these return an array of
|
880
|
+
database config objects for the requested environment and a single database config object
|
881
|
+
will be returned for the requested environment and specification name respectively.
|
867
882
|
|
868
|
-
|
883
|
+
```
|
884
|
+
ActiveRecord::Base.configurations.configs_for(env_name: "development")
|
885
|
+
ActiveRecord::Base.configurations.configs_for(env_name: "development", spec_name: "primary")
|
886
|
+
```
|
869
887
|
|
870
|
-
*
|
888
|
+
*Eileen M. Uchitelle*, *Aaron Patterson*
|
889
|
+
|
890
|
+
* Add database configuration to disable advisory locks.
|
871
891
|
|
872
|
-
|
873
|
-
|
892
|
+
```
|
893
|
+
production:
|
894
|
+
adapter: postgresql
|
895
|
+
advisory_locks: false
|
896
|
+
```
|
874
897
|
|
875
|
-
*
|
898
|
+
*Guo Xiang*
|
876
899
|
|
877
|
-
*
|
878
|
-
if the child records were deleted before the parent was saved, they would
|
879
|
-
still be persisted. Now, if child records are deleted before the parent is saved
|
880
|
-
on a `has_many :through` association, the child records will not be persisted.
|
900
|
+
* SQLite3 adapter `alter_table` method restores foreign keys.
|
881
901
|
|
882
|
-
*
|
902
|
+
*Yasuo Honda*
|
883
903
|
|
884
|
-
*
|
885
|
-
the merged relation into LEFT OUTER JOIN.
|
904
|
+
* Allow `:to_table` option to `invert_remove_foreign_key`.
|
886
905
|
|
887
906
|
Example:
|
888
907
|
|
889
|
-
|
890
|
-
Author.joins(:posts).merge(Post.joins(:comments))
|
891
|
-
# Before the change:
|
892
|
-
#=> SELECT ... FROM authors INNER JOIN posts ON ... LEFT OUTER JOIN comments ON...
|
908
|
+
remove_foreign_key :accounts, to_table: :owners
|
893
909
|
|
894
|
-
|
895
|
-
#=> SELECT ... FROM authors INNER JOIN posts ON ... INNER JOIN comments ON...
|
896
|
-
```
|
910
|
+
*Nikolay Epifanov*, *Rich Chen*
|
897
911
|
|
898
|
-
|
912
|
+
* Add environment & load_config dependency to `bin/rake db:seed` to enable
|
913
|
+
seed load in environments without Rails and custom DB configuration
|
899
914
|
|
900
|
-
*
|
901
|
-
`locking_column`, without default value, is null in the database.
|
915
|
+
*Tobias Bielohlawek*
|
902
916
|
|
903
|
-
|
917
|
+
* Fix default value for mysql time types with specified precision.
|
904
918
|
|
905
|
-
*
|
906
|
-
`locking_column` is null in the database.
|
919
|
+
*Nikolay Kondratyev*
|
907
920
|
|
908
|
-
|
921
|
+
* Fix `touch` option to behave consistently with `Persistence#touch` method.
|
909
922
|
|
910
|
-
*
|
923
|
+
*Ryuta Kamizono*
|
911
924
|
|
912
|
-
|
925
|
+
* Migrations raise when duplicate column definition.
|
913
926
|
|
914
|
-
|
927
|
+
Fixes #33024.
|
915
928
|
|
916
|
-
*
|
929
|
+
*Federico Martinez*
|
917
930
|
|
918
|
-
*
|
931
|
+
* Bump minimum SQLite version to 3.8
|
919
932
|
|
920
|
-
*
|
933
|
+
*Yasuo Honda*
|
921
934
|
|
922
|
-
*
|
935
|
+
* Fix parent record should not get saved with duplicate children records.
|
923
936
|
|
924
|
-
Fixes #
|
937
|
+
Fixes #32940.
|
925
938
|
|
926
|
-
*
|
939
|
+
*Santosh Wadghule*
|
927
940
|
|
928
|
-
*
|
929
|
-
in `ActiveSupport::Cache`. This also means that `ActiveRecord::Base#cache_key` will now return a stable key
|
930
|
-
that does not include a timestamp any more.
|
941
|
+
* Fix logic on disabling commit callbacks so they are not called unexpectedly when errors occur.
|
931
942
|
|
932
|
-
|
933
|
-
until you set `ActiveRecord::Base.cache_versioning = true`. That's the setting for all new apps on Rails 5.2+
|
943
|
+
*Brian Durand*
|
934
944
|
|
935
|
-
|
945
|
+
* Ensure `Associations::CollectionAssociation#size` and `Associations::CollectionAssociation#empty?`
|
946
|
+
use loaded association ids if present.
|
936
947
|
|
937
|
-
*
|
948
|
+
*Graham Turner*
|
938
949
|
|
939
|
-
|
950
|
+
* Add support to preload associations of polymorphic associations when not all the records have the requested associations.
|
940
951
|
|
941
|
-
*
|
952
|
+
*Dana Sherson*
|
942
953
|
|
943
|
-
|
954
|
+
* Add `touch_all` method to `ActiveRecord::Relation`.
|
944
955
|
|
945
|
-
|
956
|
+
Example:
|
946
957
|
|
947
|
-
|
958
|
+
Person.where(name: "David").touch_all(time: Time.new(2020, 5, 16, 0, 0, 0))
|
948
959
|
|
949
|
-
*
|
960
|
+
*fatkodima*, *duggiefresh*
|
950
961
|
|
951
|
-
*
|
952
|
-
when the current migration does not exist.
|
962
|
+
* Add `ActiveRecord::Base.base_class?` predicate.
|
953
963
|
|
954
|
-
*
|
964
|
+
*Bogdan Gusiev*
|
955
965
|
|
956
|
-
*
|
966
|
+
* Add custom prefix/suffix options to `ActiveRecord::Store.store_accessor`.
|
957
967
|
|
958
|
-
*
|
968
|
+
*Tan Huynh*, *Yukio Mizuta*
|
959
969
|
|
960
|
-
*
|
970
|
+
* Rails 6 requires Ruby 2.5.0 or newer.
|
961
971
|
|
962
|
-
|
963
|
-
See https://dev.mysql.com/doc/refman/8.0/en/descending-indexes.html.
|
972
|
+
*Jeremy Daer*, *Kasper Timm Hansen*
|
964
973
|
|
965
|
-
|
974
|
+
* Deprecate `update_attributes`/`!` in favor of `update`/`!`.
|
966
975
|
|
967
|
-
*
|
976
|
+
*Eddie Lebow*
|
968
977
|
|
969
|
-
|
978
|
+
* Add `ActiveRecord::Base.create_or_find_by`/`!` to deal with the SELECT/INSERT race condition in
|
979
|
+
`ActiveRecord::Base.find_or_create_by`/`!` by leaning on unique constraints in the database.
|
970
980
|
|
971
|
-
*
|
972
|
-
Previously this method always returned an empty array.
|
981
|
+
*DHH*
|
973
982
|
|
974
|
-
|
983
|
+
* Add `Relation#pick` as short-hand for single-value plucks.
|
984
|
+
|
985
|
+
*DHH*
|
975
986
|
|
976
987
|
|
977
|
-
Please check [5-
|
988
|
+
Please check [5-2-stable](https://github.com/rails/rails/blob/5-2-stable/activerecord/CHANGELOG.md) for previous changes.
|