activerecord 4.2.0 → 6.0.0
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 +5 -5
- data/CHANGELOG.md +612 -971
- data/MIT-LICENSE +4 -2
- data/README.rdoc +13 -12
- data/examples/performance.rb +33 -32
- data/examples/simple.rb +5 -4
- data/lib/active_record/aggregations.rb +267 -248
- data/lib/active_record/association_relation.rb +24 -6
- data/lib/active_record/associations/alias_tracker.rb +29 -35
- data/lib/active_record/associations/association.rb +135 -56
- data/lib/active_record/associations/association_scope.rb +103 -131
- data/lib/active_record/associations/belongs_to_association.rb +67 -54
- data/lib/active_record/associations/belongs_to_polymorphic_association.rb +8 -12
- data/lib/active_record/associations/builder/association.rb +27 -40
- data/lib/active_record/associations/builder/belongs_to.rb +69 -55
- data/lib/active_record/associations/builder/collection_association.rb +10 -29
- data/lib/active_record/associations/builder/has_and_belongs_to_many.rb +60 -70
- data/lib/active_record/associations/builder/has_many.rb +8 -4
- data/lib/active_record/associations/builder/has_one.rb +46 -5
- data/lib/active_record/associations/builder/singular_association.rb +16 -10
- data/lib/active_record/associations/collection_association.rb +138 -274
- data/lib/active_record/associations/collection_proxy.rb +252 -151
- data/lib/active_record/associations/foreign_association.rb +20 -0
- data/lib/active_record/associations/has_many_association.rb +35 -83
- data/lib/active_record/associations/has_many_through_association.rb +62 -80
- data/lib/active_record/associations/has_one_association.rb +62 -49
- data/lib/active_record/associations/has_one_through_association.rb +20 -11
- data/lib/active_record/associations/join_dependency/join_association.rb +38 -80
- data/lib/active_record/associations/join_dependency/join_base.rb +10 -9
- data/lib/active_record/associations/join_dependency/join_part.rb +14 -14
- data/lib/active_record/associations/join_dependency.rb +138 -162
- data/lib/active_record/associations/preloader/association.rb +90 -119
- data/lib/active_record/associations/preloader/through_association.rb +85 -65
- data/lib/active_record/associations/preloader.rb +92 -94
- data/lib/active_record/associations/singular_association.rb +18 -45
- data/lib/active_record/associations/through_association.rb +48 -23
- data/lib/active_record/associations.rb +1737 -1596
- data/lib/active_record/attribute_assignment.rb +56 -183
- data/lib/active_record/attribute_decorators.rb +39 -15
- data/lib/active_record/attribute_methods/before_type_cast.rb +15 -5
- data/lib/active_record/attribute_methods/dirty.rb +174 -134
- data/lib/active_record/attribute_methods/primary_key.rb +91 -83
- data/lib/active_record/attribute_methods/query.rb +6 -5
- data/lib/active_record/attribute_methods/read.rb +20 -76
- data/lib/active_record/attribute_methods/serialization.rb +40 -20
- data/lib/active_record/attribute_methods/time_zone_conversion.rb +62 -36
- data/lib/active_record/attribute_methods/write.rb +33 -55
- data/lib/active_record/attribute_methods.rb +124 -143
- data/lib/active_record/attributes.rb +214 -74
- data/lib/active_record/autosave_association.rb +115 -46
- data/lib/active_record/base.rb +60 -49
- data/lib/active_record/callbacks.rb +100 -74
- data/lib/active_record/coders/json.rb +3 -1
- data/lib/active_record/coders/yaml_column.rb +24 -12
- data/lib/active_record/connection_adapters/abstract/connection_pool.rb +796 -290
- data/lib/active_record/connection_adapters/abstract/database_limits.rb +26 -8
- data/lib/active_record/connection_adapters/abstract/database_statements.rb +247 -108
- data/lib/active_record/connection_adapters/abstract/query_cache.rb +82 -23
- data/lib/active_record/connection_adapters/abstract/quoting.rb +171 -53
- data/lib/active_record/connection_adapters/abstract/savepoints.rb +6 -4
- data/lib/active_record/connection_adapters/abstract/schema_creation.rb +74 -46
- data/lib/active_record/connection_adapters/abstract/schema_definitions.rb +366 -227
- data/lib/active_record/connection_adapters/abstract/schema_dumper.rb +79 -36
- data/lib/active_record/connection_adapters/abstract/schema_statements.rb +706 -222
- data/lib/active_record/connection_adapters/abstract/transaction.rb +191 -87
- data/lib/active_record/connection_adapters/abstract_adapter.rb +468 -194
- data/lib/active_record/connection_adapters/abstract_mysql_adapter.rb +535 -597
- data/lib/active_record/connection_adapters/column.rb +56 -43
- data/lib/active_record/connection_adapters/connection_specification.rb +174 -152
- data/lib/active_record/connection_adapters/determine_if_preparable_visitor.rb +29 -0
- data/lib/active_record/connection_adapters/mysql/column.rb +27 -0
- data/lib/active_record/connection_adapters/mysql/database_statements.rb +200 -0
- data/lib/active_record/connection_adapters/mysql/explain_pretty_printer.rb +72 -0
- data/lib/active_record/connection_adapters/mysql/quoting.rb +81 -0
- data/lib/active_record/connection_adapters/mysql/schema_creation.rb +72 -0
- data/lib/active_record/connection_adapters/mysql/schema_definitions.rb +95 -0
- data/lib/active_record/connection_adapters/mysql/schema_dumper.rb +88 -0
- data/lib/active_record/connection_adapters/mysql/schema_statements.rb +264 -0
- data/lib/active_record/connection_adapters/mysql/type_metadata.rb +31 -0
- data/lib/active_record/connection_adapters/mysql2_adapter.rb +59 -195
- data/lib/active_record/connection_adapters/postgresql/column.rb +21 -11
- data/lib/active_record/connection_adapters/postgresql/database_statements.rb +65 -115
- data/lib/active_record/connection_adapters/postgresql/explain_pretty_printer.rb +44 -0
- data/lib/active_record/connection_adapters/postgresql/oid/array.rb +50 -57
- data/lib/active_record/connection_adapters/postgresql/oid/bit.rb +9 -8
- data/lib/active_record/connection_adapters/postgresql/oid/bit_varying.rb +2 -0
- data/lib/active_record/connection_adapters/postgresql/oid/bytea.rb +5 -2
- data/lib/active_record/connection_adapters/postgresql/oid/cidr.rb +5 -1
- data/lib/active_record/connection_adapters/postgresql/oid/date.rb +13 -1
- data/lib/active_record/connection_adapters/postgresql/oid/date_time.rb +9 -13
- data/lib/active_record/connection_adapters/postgresql/oid/decimal.rb +3 -1
- data/lib/active_record/connection_adapters/postgresql/oid/enum.rb +7 -3
- data/lib/active_record/connection_adapters/postgresql/oid/hstore.rb +31 -19
- data/lib/active_record/connection_adapters/postgresql/oid/inet.rb +2 -0
- data/lib/active_record/connection_adapters/postgresql/oid/jsonb.rb +3 -11
- data/lib/active_record/connection_adapters/postgresql/oid/legacy_point.rb +45 -0
- data/lib/active_record/connection_adapters/postgresql/oid/money.rb +7 -9
- data/lib/active_record/connection_adapters/postgresql/oid/{integer.rb → oid.rb} +6 -2
- data/lib/active_record/connection_adapters/postgresql/oid/point.rb +33 -11
- data/lib/active_record/connection_adapters/postgresql/oid/range.rb +52 -34
- data/lib/active_record/connection_adapters/postgresql/oid/specialized_string.rb +4 -1
- data/lib/active_record/connection_adapters/postgresql/oid/type_map_initializer.rb +67 -51
- data/lib/active_record/connection_adapters/postgresql/oid/uuid.rb +10 -5
- data/lib/active_record/connection_adapters/postgresql/oid/vector.rb +3 -1
- data/lib/active_record/connection_adapters/postgresql/oid/xml.rb +3 -1
- data/lib/active_record/connection_adapters/postgresql/oid.rb +23 -25
- data/lib/active_record/connection_adapters/postgresql/quoting.rb +144 -47
- data/lib/active_record/connection_adapters/postgresql/referential_integrity.rb +27 -14
- data/lib/active_record/connection_adapters/postgresql/schema_creation.rb +76 -0
- data/lib/active_record/connection_adapters/postgresql/schema_definitions.rb +178 -108
- data/lib/active_record/connection_adapters/postgresql/schema_dumper.rb +50 -0
- data/lib/active_record/connection_adapters/postgresql/schema_statements.rb +474 -286
- data/lib/active_record/connection_adapters/postgresql/type_metadata.rb +36 -0
- data/lib/active_record/connection_adapters/postgresql/utils.rb +12 -8
- data/lib/active_record/connection_adapters/postgresql_adapter.rb +558 -363
- data/lib/active_record/connection_adapters/schema_cache.rb +72 -25
- data/lib/active_record/connection_adapters/sql_type_metadata.rb +37 -0
- data/lib/active_record/connection_adapters/sqlite3/database_statements.rb +118 -0
- data/lib/active_record/connection_adapters/sqlite3/explain_pretty_printer.rb +21 -0
- data/lib/active_record/connection_adapters/sqlite3/quoting.rb +103 -0
- data/lib/active_record/connection_adapters/sqlite3/schema_creation.rb +17 -0
- data/lib/active_record/connection_adapters/sqlite3/schema_definitions.rb +19 -0
- data/lib/active_record/connection_adapters/sqlite3/schema_dumper.rb +18 -0
- data/lib/active_record/connection_adapters/sqlite3/schema_statements.rb +137 -0
- data/lib/active_record/connection_adapters/sqlite3_adapter.rb +288 -359
- data/lib/active_record/connection_adapters/statement_pool.rb +34 -13
- data/lib/active_record/connection_handling.rb +176 -41
- data/lib/active_record/core.rb +266 -233
- data/lib/active_record/counter_cache.rb +68 -50
- 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/database_configurations.rb +233 -0
- data/lib/active_record/define_callbacks.rb +22 -0
- data/lib/active_record/dynamic_matchers.rb +87 -105
- data/lib/active_record/enum.rb +164 -88
- data/lib/active_record/errors.rb +189 -53
- data/lib/active_record/explain.rb +23 -11
- data/lib/active_record/explain_registry.rb +4 -2
- data/lib/active_record/explain_subscriber.rb +11 -6
- data/lib/active_record/fixture_set/file.rb +35 -9
- 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 +226 -495
- data/lib/active_record/gem_version.rb +4 -2
- data/lib/active_record/inheritance.rb +158 -112
- data/lib/active_record/insert_all.rb +179 -0
- data/lib/active_record/integration.rb +123 -29
- data/lib/active_record/internal_metadata.rb +53 -0
- data/lib/active_record/legacy_yaml_adapter.rb +48 -0
- data/lib/active_record/locale/en.yml +3 -2
- data/lib/active_record/locking/optimistic.rb +91 -98
- data/lib/active_record/locking/pessimistic.rb +18 -6
- data/lib/active_record/log_subscriber.rb +76 -33
- data/lib/active_record/middleware/database_selector/resolver/session.rb +45 -0
- data/lib/active_record/middleware/database_selector/resolver.rb +92 -0
- data/lib/active_record/middleware/database_selector.rb +75 -0
- data/lib/active_record/migration/command_recorder.rb +177 -90
- data/lib/active_record/migration/compatibility.rb +244 -0
- data/lib/active_record/migration/join_table.rb +8 -6
- data/lib/active_record/migration.rb +634 -288
- data/lib/active_record/model_schema.rb +314 -112
- data/lib/active_record/nested_attributes.rb +266 -214
- data/lib/active_record/no_touching.rb +15 -2
- data/lib/active_record/null_relation.rb +24 -37
- data/lib/active_record/persistence.rb +559 -124
- data/lib/active_record/query_cache.rb +19 -23
- data/lib/active_record/querying.rb +43 -29
- data/lib/active_record/railtie.rb +148 -47
- data/lib/active_record/railties/collection_cache_association_loading.rb +34 -0
- data/lib/active_record/railties/console_sandbox.rb +2 -0
- data/lib/active_record/railties/controller_runtime.rb +34 -33
- data/lib/active_record/railties/databases.rake +338 -202
- data/lib/active_record/readonly_attributes.rb +5 -4
- data/lib/active_record/reflection.rb +460 -299
- data/lib/active_record/relation/batches/batch_enumerator.rb +69 -0
- data/lib/active_record/relation/batches.rb +207 -55
- data/lib/active_record/relation/calculations.rb +269 -248
- data/lib/active_record/relation/delegation.rb +70 -80
- data/lib/active_record/relation/finder_methods.rb +279 -255
- data/lib/active_record/relation/from_clause.rb +26 -0
- data/lib/active_record/relation/merger.rb +83 -69
- data/lib/active_record/relation/predicate_builder/array_handler.rb +27 -25
- data/lib/active_record/relation/predicate_builder/association_query_value.rb +43 -0
- data/lib/active_record/relation/predicate_builder/base_handler.rb +18 -0
- data/lib/active_record/relation/predicate_builder/basic_object_handler.rb +19 -0
- data/lib/active_record/relation/predicate_builder/polymorphic_array_value.rb +53 -0
- data/lib/active_record/relation/predicate_builder/range_handler.rb +22 -0
- data/lib/active_record/relation/predicate_builder/relation_handler.rb +7 -1
- data/lib/active_record/relation/predicate_builder.rb +116 -92
- data/lib/active_record/relation/query_attribute.rb +50 -0
- data/lib/active_record/relation/query_methods.rb +574 -391
- data/lib/active_record/relation/record_fetch_warning.rb +51 -0
- data/lib/active_record/relation/spawn_methods.rb +18 -16
- data/lib/active_record/relation/where_clause.rb +190 -0
- data/lib/active_record/relation/where_clause_factory.rb +33 -0
- data/lib/active_record/relation.rb +518 -340
- data/lib/active_record/result.rb +79 -42
- data/lib/active_record/runtime_registry.rb +6 -4
- data/lib/active_record/sanitization.rb +144 -121
- data/lib/active_record/schema.rb +21 -24
- data/lib/active_record/schema_dumper.rb +112 -93
- data/lib/active_record/schema_migration.rb +24 -20
- data/lib/active_record/scoping/default.rb +101 -84
- data/lib/active_record/scoping/named.rb +86 -33
- data/lib/active_record/scoping.rb +45 -26
- data/lib/active_record/secure_token.rb +40 -0
- data/lib/active_record/serialization.rb +5 -5
- data/lib/active_record/statement_cache.rb +73 -36
- data/lib/active_record/store.rb +127 -42
- data/lib/active_record/suppressor.rb +61 -0
- data/lib/active_record/table_metadata.rb +75 -0
- data/lib/active_record/tasks/database_tasks.rb +309 -99
- data/lib/active_record/tasks/mysql_database_tasks.rb +58 -88
- data/lib/active_record/tasks/postgresql_database_tasks.rb +82 -31
- data/lib/active_record/tasks/sqlite_database_tasks.rb +38 -16
- data/lib/active_record/test_databases.rb +23 -0
- data/lib/active_record/test_fixtures.rb +224 -0
- data/lib/active_record/timestamp.rb +86 -40
- data/lib/active_record/touch_later.rb +66 -0
- data/lib/active_record/transactions.rb +215 -139
- data/lib/active_record/translation.rb +3 -1
- data/lib/active_record/type/adapter_specific_registry.rb +129 -0
- data/lib/active_record/type/date.rb +4 -41
- data/lib/active_record/type/date_time.rb +4 -38
- data/lib/active_record/type/decimal_without_scale.rb +6 -2
- data/lib/active_record/type/hash_lookup_type_map.rb +13 -5
- data/lib/active_record/type/internal/timezone.rb +17 -0
- data/lib/active_record/type/json.rb +30 -0
- data/lib/active_record/type/serialized.rb +30 -15
- data/lib/active_record/type/text.rb +2 -2
- data/lib/active_record/type/time.rb +11 -16
- data/lib/active_record/type/type_map.rb +15 -17
- data/lib/active_record/type/unsigned_integer.rb +9 -7
- data/lib/active_record/type.rb +78 -23
- data/lib/active_record/type_caster/connection.rb +34 -0
- data/lib/active_record/type_caster/map.rb +20 -0
- data/lib/active_record/type_caster.rb +9 -0
- data/lib/active_record/validations/absence.rb +25 -0
- data/lib/active_record/validations/associated.rb +13 -4
- data/lib/active_record/validations/length.rb +26 -0
- data/lib/active_record/validations/presence.rb +14 -13
- data/lib/active_record/validations/uniqueness.rb +43 -46
- data/lib/active_record/validations.rb +39 -35
- data/lib/active_record/version.rb +3 -1
- data/lib/active_record.rb +43 -21
- data/lib/arel/alias_predication.rb +9 -0
- data/lib/arel/attributes/attribute.rb +37 -0
- data/lib/arel/attributes.rb +22 -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/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/nodes.rb +68 -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/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/visitors.rb +20 -0
- data/lib/arel/window_predications.rb +9 -0
- data/lib/arel.rb +51 -0
- data/lib/rails/generators/active_record/application_record/application_record_generator.rb +27 -0
- data/lib/rails/generators/active_record/application_record/templates/application_record.rb.tt +5 -0
- data/lib/rails/generators/active_record/migration/migration_generator.rb +42 -37
- data/lib/rails/generators/active_record/migration/templates/create_table_migration.rb.tt +24 -0
- data/lib/rails/generators/active_record/migration/templates/{migration.rb → migration.rb.tt} +11 -8
- data/lib/rails/generators/active_record/migration.rb +31 -1
- data/lib/rails/generators/active_record/model/model_generator.rb +19 -22
- data/lib/rails/generators/active_record/model/templates/model.rb.tt +22 -0
- data/lib/rails/generators/active_record.rb +7 -5
- metadata +166 -60
- data/lib/active_record/associations/preloader/belongs_to.rb +0 -17
- data/lib/active_record/associations/preloader/collection_association.rb +0 -24
- data/lib/active_record/associations/preloader/has_many.rb +0 -17
- data/lib/active_record/associations/preloader/has_many_through.rb +0 -19
- data/lib/active_record/associations/preloader/has_one.rb +0 -23
- data/lib/active_record/associations/preloader/has_one_through.rb +0 -9
- data/lib/active_record/associations/preloader/singular_association.rb +0 -21
- data/lib/active_record/attribute.rb +0 -149
- data/lib/active_record/attribute_set/builder.rb +0 -86
- data/lib/active_record/attribute_set.rb +0 -77
- data/lib/active_record/connection_adapters/mysql_adapter.rb +0 -491
- data/lib/active_record/connection_adapters/postgresql/array_parser.rb +0 -93
- data/lib/active_record/connection_adapters/postgresql/oid/float.rb +0 -21
- data/lib/active_record/connection_adapters/postgresql/oid/infinity.rb +0 -13
- data/lib/active_record/connection_adapters/postgresql/oid/json.rb +0 -35
- data/lib/active_record/connection_adapters/postgresql/oid/time.rb +0 -11
- data/lib/active_record/railties/jdbcmysql_error.rb +0 -16
- data/lib/active_record/serializers/xml_serializer.rb +0 -193
- data/lib/active_record/type/big_integer.rb +0 -13
- data/lib/active_record/type/binary.rb +0 -50
- data/lib/active_record/type/boolean.rb +0 -30
- data/lib/active_record/type/decimal.rb +0 -40
- data/lib/active_record/type/decorator.rb +0 -14
- data/lib/active_record/type/float.rb +0 -19
- data/lib/active_record/type/integer.rb +0 -55
- data/lib/active_record/type/mutable.rb +0 -16
- data/lib/active_record/type/numeric.rb +0 -36
- data/lib/active_record/type/string.rb +0 -36
- data/lib/active_record/type/time_value.rb +0 -38
- data/lib/active_record/type/value.rb +0 -101
- data/lib/rails/generators/active_record/migration/templates/create_table_migration.rb +0 -22
- data/lib/rails/generators/active_record/model/templates/model.rb +0 -10
- /data/lib/rails/generators/active_record/model/templates/{module.rb → module.rb.tt} +0 -0
data/CHANGELOG.md
CHANGED
@@ -1,1372 +1,1013 @@
|
|
1
|
-
|
2
|
-
will recreate tables even if they have dependent objects (like foreign keys).
|
3
|
-
`db/schema.rb` now uses `force: :cascade`. This makes it possible to
|
4
|
-
reload the schema when foreign keys are in place.
|
1
|
+
## Rails 6.0.0 (August 16, 2019) ##
|
5
2
|
|
6
|
-
|
3
|
+
* Preserve user supplied joins order as much as possible.
|
7
4
|
|
8
|
-
|
9
|
-
before loading the schema. This is left for the user to do.
|
10
|
-
`db:test:prepare` will still purge the database.
|
11
|
-
|
12
|
-
Closes #17945.
|
13
|
-
|
14
|
-
*Yves Senn*
|
15
|
-
|
16
|
-
* Fix undesirable RangeError by Type::Integer. Add Type::UnsignedInteger.
|
5
|
+
Fixes #36761, #34328, #24281, #12953.
|
17
6
|
|
18
7
|
*Ryuta Kamizono*
|
19
8
|
|
20
|
-
*
|
21
|
-
|
22
|
-
This option enables to define the column name of associated object's type for polymorphic associations.
|
23
|
-
|
24
|
-
*Ulisses Almeida, Kassio Borges*
|
25
|
-
|
26
|
-
* `add_timestamps` and `remove_timestamps` now properly reversible with
|
27
|
-
options.
|
28
|
-
|
29
|
-
*Noam Gagliardi-Rabinovich*
|
30
|
-
|
31
|
-
* Bring back `db:test:prepare` to synchronize the test database schema.
|
32
|
-
|
33
|
-
Manual synchronization using `bin/rake db:test:prepare` is required
|
34
|
-
when a migration is rolled-back, edited and reapplied.
|
35
|
-
|
36
|
-
`ActiveRecord::Base.maintain_test_schema` now uses `db:test:prepare`
|
37
|
-
to synchronize the schema. Plugins can use this task as a hook to
|
38
|
-
provide custom behavior after the schema has been loaded.
|
39
|
-
|
40
|
-
NOTE: `test:prepare` runs before the schema is synchronized.
|
41
|
-
|
42
|
-
Fixes #17171, #15787.
|
43
|
-
|
44
|
-
*Yves Senn*
|
45
|
-
|
46
|
-
* Change `reflections` public api to return the keys as String objects.
|
47
|
-
|
48
|
-
Fixes #16928.
|
49
|
-
|
50
|
-
*arthurnn*
|
51
|
-
|
52
|
-
* Renaming a table in pg also renames the primary key index.
|
53
|
-
|
54
|
-
Fixes #12856
|
55
|
-
|
56
|
-
*Sean Griffin*
|
57
|
-
|
58
|
-
* Make it possible to access fixtures excluded by a `default_scope`.
|
59
|
-
|
60
|
-
*Yves Senn*
|
61
|
-
|
62
|
-
* Fix preloading of associations with a scope containing joins along with
|
63
|
-
conditions on the joined association.
|
64
|
-
|
65
|
-
*Siddharth Sharma*
|
66
|
-
|
67
|
-
* Add `Table#name` to match `TableDefinition#name`.
|
68
|
-
|
69
|
-
*Cody Cutrer*
|
70
|
-
|
71
|
-
* Cache `CollectionAssociation#reader` proxies separately before and after
|
72
|
-
the owner has been saved so that the proxy is not cached without the
|
73
|
-
owner's id.
|
74
|
-
|
75
|
-
*Ben Woosley*
|
76
|
-
|
77
|
-
* `ActiveRecord::ReadOnlyRecord` now has a descriptive message.
|
78
|
-
|
79
|
-
*Franky W.*
|
80
|
-
|
81
|
-
* Fix preloading of associations which unscope a default scope.
|
82
|
-
|
83
|
-
Fixes #11036.
|
84
|
-
|
85
|
-
*Byron Bischoff*
|
86
|
-
|
87
|
-
* Added SchemaDumper support for tables with jsonb columns.
|
88
|
-
|
89
|
-
*Ted O'Meara*
|
90
|
-
|
91
|
-
* Deprecate `sanitize_sql_hash_for_conditions` without replacement. Using a
|
92
|
-
`Relation` for performing queries and updates is the prefered API.
|
93
|
-
|
94
|
-
*Sean Griffin*
|
95
|
-
|
96
|
-
* Queries now properly type cast values that are part of a join statement,
|
97
|
-
even when using type decorators such as `serialize`.
|
98
|
-
|
99
|
-
*Melanie Gilman & Sean Griffin*
|
100
|
-
|
101
|
-
* MySQL enum type lookups, with values matching another type, no longer result
|
102
|
-
in an endless loop.
|
103
|
-
|
104
|
-
Fixes #17402.
|
105
|
-
|
106
|
-
*Yves Senn*
|
107
|
-
|
108
|
-
* Raise `ArgumentError` when the body of a scope is not callable.
|
109
|
-
|
110
|
-
*Mauro George*
|
111
|
-
|
112
|
-
* Use type column first in multi-column indexes created with `add-reference`.
|
113
|
-
|
114
|
-
*Derek Prior*
|
115
|
-
|
116
|
-
* Fix `Relation.rewhere` to work with Range values.
|
117
|
-
|
118
|
-
*Dan Olson*
|
119
|
-
|
120
|
-
* `AR::UnknownAttributeError` now includes the class name of a record.
|
121
|
-
|
122
|
-
User.new(name: "Yuki Nishijima", project_attributes: {name: "kaminari"})
|
123
|
-
# => ActiveRecord::UnknownAttributeError: unknown attribute 'name' for User.
|
124
|
-
|
125
|
-
*Yuki Nishijima*
|
126
|
-
|
127
|
-
* Fix a regression causing `after_create` callbacks to run before associated
|
128
|
-
records are autosaved.
|
129
|
-
|
130
|
-
Fixes #17209.
|
131
|
-
|
132
|
-
*Agis Anastasopoulos*
|
133
|
-
|
134
|
-
* Honor overridden `rack.test` in Rack environment for the connection
|
135
|
-
management middleware.
|
136
|
-
|
137
|
-
*Simon Eskildsen*
|
138
|
-
|
139
|
-
* Add a truncate method to the connection.
|
140
|
-
|
141
|
-
*Aaron Patterson*
|
142
|
-
|
143
|
-
* Don't autosave unchanged has_one through records.
|
144
|
-
|
145
|
-
*Alan Kennedy*, *Steve Parrington*
|
146
|
-
|
147
|
-
* Do not dump foreign keys for ignored tables.
|
148
|
-
|
149
|
-
*Yves Senn*
|
150
|
-
|
151
|
-
* PostgreSQL adapter correctly dumps foreign keys targeting tables
|
152
|
-
outside the schema search path.
|
153
|
-
|
154
|
-
Fixes #16907.
|
155
|
-
|
156
|
-
*Matthew Draper*, *Yves Senn*
|
157
|
-
|
158
|
-
* When a thread is killed, rollback the active transaction, instead of
|
159
|
-
committing it during the stack unwind. Previously, we could commit half-
|
160
|
-
completed work. This fix only works for Ruby 2.0+; on 1.9, we can't
|
161
|
-
distinguish a thread kill from an ordinary non-local (block) return, so must
|
162
|
-
default to committing.
|
163
|
-
|
164
|
-
*Chris Hanks*
|
165
|
-
|
166
|
-
* A `NullRelation` should represent nothing. This fixes a bug where
|
167
|
-
`Comment.where(post_id: Post.none)` returned a non-empty result.
|
168
|
-
|
169
|
-
Fixes #15176.
|
9
|
+
* Make the DATABASE_URL env variable only affect the primary connection. Add new env variables for multiple databases.
|
170
10
|
|
171
|
-
*
|
11
|
+
*John Crepezzi*, *Eileen Uchitelle*
|
172
12
|
|
173
|
-
*
|
174
|
-
in the future without affecting old migrations that assumed old defaults.
|
13
|
+
* Add a warning for enum elements with 'not_' prefix.
|
175
14
|
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
*Jeremy Kemper*
|
181
|
-
|
182
|
-
* MySQL: correct LONGTEXT and LONGBLOB limits from 2GB to their true 4GB.
|
183
|
-
|
184
|
-
*Jeremy Kemper*
|
185
|
-
|
186
|
-
* SQLite3Adapter now checks for views in `table_exists?`. Fixes #14041.
|
187
|
-
|
188
|
-
*Girish Sonawane*
|
189
|
-
|
190
|
-
* Introduce `connection.supports_views?` to check whether the current adapter
|
191
|
-
has support for SQL views. Connection adapters should define this method.
|
192
|
-
|
193
|
-
*Yves Senn*
|
194
|
-
|
195
|
-
* Allow included modules to override association methods.
|
196
|
-
|
197
|
-
Fixes #16684.
|
198
|
-
|
199
|
-
*Yves Senn*
|
15
|
+
class Foo
|
16
|
+
enum status: [:sent, :not_sent]
|
17
|
+
end
|
200
18
|
|
201
|
-
*
|
202
|
-
the database connection to the current environment.
|
19
|
+
*Edu Depetris*
|
203
20
|
|
204
|
-
|
21
|
+
* Make currency symbols optional for money column type in PostgreSQL
|
205
22
|
|
206
|
-
*
|
23
|
+
*Joel Schneider*
|
207
24
|
|
208
|
-
* MySQL: set the connection collation along with the charset.
|
209
25
|
|
210
|
-
|
211
|
-
database.yml. Otherwise, `SET NAMES utf8mb4` will use the default
|
212
|
-
collation for that charset (utf8mb4_general_ci) when you may have chosen
|
213
|
-
a different collation, like utf8mb4_unicode_ci.
|
26
|
+
## Rails 6.0.0.rc2 (July 22, 2019) ##
|
214
27
|
|
215
|
-
|
216
|
-
is unlikely to affect you.
|
28
|
+
* Add database_exists? method to connection adapters to check if a database exists.
|
217
29
|
|
218
|
-
*
|
30
|
+
*Guilherme Mansur*
|
219
31
|
|
220
|
-
*
|
32
|
+
* PostgreSQL: Fix GROUP BY with ORDER BY virtual count attribute.
|
221
33
|
|
222
|
-
|
34
|
+
Fixes #36022.
|
223
35
|
|
224
|
-
*
|
225
|
-
PostgreSQL.
|
36
|
+
*Ryuta Kamizono*
|
226
37
|
|
227
|
-
|
38
|
+
* Make ActiveRecord `ConnectionPool.connections` method thread-safe.
|
228
39
|
|
229
|
-
Fixes #
|
40
|
+
Fixes #36465.
|
230
41
|
|
231
|
-
*
|
232
|
-
passed as a lambda with an arity of one.
|
42
|
+
*Jeff Doering*
|
233
43
|
|
234
|
-
|
44
|
+
* Fix sqlite3 collation parsing when using decimal columns.
|
235
45
|
|
236
|
-
*
|
46
|
+
*Martin R. Schuster*
|
237
47
|
|
238
|
-
* Fix
|
48
|
+
* Fix invalid schema when primary key column has a comment.
|
239
49
|
|
240
|
-
Fixes #
|
50
|
+
Fixes #29966.
|
241
51
|
|
242
|
-
*
|
52
|
+
*Guilherme Goettems Schneider*
|
243
53
|
|
244
|
-
*
|
245
|
-
`after_rollback`/`after_create` callbacks and prints them to the logs.
|
246
|
-
Future versions of Rails will not rescue these errors anymore and
|
247
|
-
just bubble them up like the other callbacks.
|
54
|
+
* Fix table comment also being applied to the primary key column.
|
248
55
|
|
249
|
-
|
56
|
+
*Guilherme Goettems Schneider*
|
250
57
|
|
251
|
-
|
58
|
+
* Fix merging left_joins to maintain its own `join_type` context.
|
252
59
|
|
253
|
-
|
254
|
-
config.active_record.raise_in_transactional_callbacks = true
|
60
|
+
Fixes #36103.
|
255
61
|
|
256
|
-
|
257
|
-
|
258
|
-
*arthurnn*
|
62
|
+
*Ryuta Kamizono*
|
259
63
|
|
260
|
-
* Fix an issue where custom accessor methods (such as those generated by
|
261
|
-
`enum`) with the same name as a global method are incorrectly overridden
|
262
|
-
when subclassing.
|
263
64
|
|
264
|
-
|
65
|
+
## Rails 6.0.0.rc1 (April 24, 2019) ##
|
265
66
|
|
266
|
-
|
67
|
+
* Add `touch` option to `has_one` association.
|
267
68
|
|
268
|
-
*
|
269
|
-
well.
|
69
|
+
*Abhay Nikam*
|
270
70
|
|
271
|
-
|
71
|
+
* Deprecate `where.not` working as NOR and will be changed to NAND in Rails 6.1.
|
272
72
|
|
273
|
-
|
73
|
+
```ruby
|
74
|
+
all = [treasures(:diamond), treasures(:sapphire), cars(:honda), treasures(:sapphire)]
|
75
|
+
assert_equal all, PriceEstimate.all.map(&:estimate_of)
|
76
|
+
```
|
274
77
|
|
275
|
-
|
78
|
+
In Rails 6.0:
|
276
79
|
|
277
|
-
|
80
|
+
```ruby
|
81
|
+
sapphire = treasures(:sapphire)
|
278
82
|
|
279
|
-
|
83
|
+
nor = all.reject { |e|
|
84
|
+
e.estimate_of_type == sapphire.class.polymorphic_name
|
85
|
+
}.reject { |e|
|
86
|
+
e.estimate_of_id == sapphire.id
|
87
|
+
}
|
88
|
+
assert_equal [cars(:honda)], nor
|
280
89
|
|
281
|
-
|
90
|
+
without_sapphire = PriceEstimate.where.not(
|
91
|
+
estimate_of_type: sapphire.class.polymorphic_name, estimate_of_id: sapphire.id
|
92
|
+
)
|
93
|
+
assert_equal nor, without_sapphire.map(&:estimate_of)
|
94
|
+
```
|
282
95
|
|
283
|
-
|
96
|
+
In Rails 6.1:
|
284
97
|
|
285
|
-
|
98
|
+
```ruby
|
99
|
+
sapphire = treasures(:sapphire)
|
286
100
|
|
287
|
-
|
101
|
+
nand = all - [sapphire]
|
102
|
+
assert_equal [treasures(:diamond), cars(:honda)], nand
|
288
103
|
|
289
|
-
|
104
|
+
without_sapphire = PriceEstimate.where.not(
|
105
|
+
estimate_of_type: sapphire.class.polymorphic_name, estimate_of_id: sapphire.id
|
106
|
+
)
|
107
|
+
assert_equal nand, without_sapphire.map(&:estimate_of)
|
108
|
+
```
|
290
109
|
|
291
|
-
|
292
|
-
index_exists? :articles, :title, name: "idx_title" # => `true`
|
293
|
-
index_exists? :articles, :body, name: "idx_title" # => `true`
|
110
|
+
*Ryuta Kamizono*
|
294
111
|
|
295
|
-
|
296
|
-
index_exists? :articles, :title, name: "idx_title" # => `true`
|
297
|
-
index_exists? :articles, :body, name: "idx_title" # => `false`
|
112
|
+
* Fix dirty tracking after rollback.
|
298
113
|
|
299
|
-
|
114
|
+
Fixes #15018, #30167, #33868.
|
300
115
|
|
301
|
-
*
|
302
|
-
Not passing the option is deprecated but the default is still `null: true`.
|
303
|
-
With Rails 5 this will change to `null: false`.
|
116
|
+
*Ryuta Kamizono*
|
304
117
|
|
305
|
-
|
118
|
+
* Add `ActiveRecord::Relation#cache_version` to support recyclable cache keys via
|
119
|
+
the versioned entries in `ActiveSupport::Cache`. This also means that
|
120
|
+
`ActiveRecord::Relation#cache_key` will now return a stable key that does not
|
121
|
+
include the max timestamp or count any more.
|
306
122
|
|
307
|
-
|
308
|
-
|
309
|
-
|
123
|
+
NOTE: This feature is turned off by default, and `cache_key` will still return
|
124
|
+
cache keys with timestamps until you set `ActiveRecord::Base.collection_cache_versioning = true`.
|
125
|
+
That's the setting for all new apps on Rails 6.0+
|
310
126
|
|
311
127
|
*Lachlan Sylvester*
|
312
128
|
|
313
|
-
*
|
314
|
-
|
315
|
-
Currently when we call `id_was` and we have a custom primary key name,
|
316
|
-
Active Record will return the current value of the primary key. This
|
317
|
-
makes it impossible to correctly do an update operation if you change the
|
318
|
-
id.
|
319
|
-
|
320
|
-
Fixes #16413.
|
321
|
-
|
322
|
-
*Rafael Mendonça França*
|
323
|
-
|
324
|
-
* Deprecate `DatabaseTasks.load_schema` to act on the current connection.
|
325
|
-
Use `.load_schema_current` instead. In the future `load_schema` will
|
326
|
-
require the `configuration` to act on as an argument.
|
327
|
-
|
328
|
-
*Yves Senn*
|
329
|
-
|
330
|
-
* Fix automatic maintaining test schema to properly handle sql structure
|
331
|
-
schema format.
|
332
|
-
|
333
|
-
Fixes #15394.
|
334
|
-
|
335
|
-
*Wojciech Wnętrzak*
|
336
|
-
|
337
|
-
* Fix type casting to Decimal from Float with large precision.
|
338
|
-
|
339
|
-
*Tomohiro Hashidate*
|
340
|
-
|
341
|
-
* Deprecate `Reflection#source_macro`
|
342
|
-
|
343
|
-
`Reflection#source_macro` is no longer needed in Active Record
|
344
|
-
source so it has been deprecated. Code that used `source_macro`
|
345
|
-
was removed in #16353.
|
346
|
-
|
347
|
-
*Eileen M. Uchtitelle*, *Aaron Patterson*
|
129
|
+
* Fix dirty tracking for `touch` to track saved changes.
|
348
130
|
|
349
|
-
|
131
|
+
Fixes #33429.
|
350
132
|
|
351
|
-
|
352
|
-
|
353
|
-
*Kenn Ejima*
|
354
|
-
|
355
|
-
* Add support for PostgreSQL JSONB.
|
356
|
-
|
357
|
-
Example:
|
358
|
-
|
359
|
-
create_table :posts do |t|
|
360
|
-
t.jsonb :meta_data
|
361
|
-
end
|
362
|
-
|
363
|
-
*Philippe Creux*, *Chris Teague*
|
364
|
-
|
365
|
-
* `db:purge` with MySQL respects `Rails.env`.
|
366
|
-
|
367
|
-
*Yves Senn*
|
368
|
-
|
369
|
-
* `change_column_default :table, :column, nil` with PostgreSQL will issue a
|
370
|
-
`DROP DEFAULT` instead of a `DEFAULT NULL` query.
|
371
|
-
|
372
|
-
Fixes #16261.
|
373
|
-
|
374
|
-
*Matthew Draper*, *Yves Senn*
|
375
|
-
|
376
|
-
* Allow to specify a type for the foreign key column in `references`
|
377
|
-
and `add_reference`.
|
378
|
-
|
379
|
-
Example:
|
380
|
-
|
381
|
-
change_table :vehicle do |t|
|
382
|
-
t.references :station, type: :uuid
|
383
|
-
end
|
384
|
-
|
385
|
-
*Andrey Novikov*, *Łukasz Sarnacki*
|
386
|
-
|
387
|
-
* `create_join_table` removes a common prefix when generating the join table.
|
388
|
-
This matches the existing behavior of HABTM associations.
|
389
|
-
|
390
|
-
Fixes #13683.
|
391
|
-
|
392
|
-
*Stefan Kanev*
|
393
|
-
|
394
|
-
* Do not swallow errors on `compute_type` when having a bad `alias_method` on
|
395
|
-
a class.
|
396
|
-
|
397
|
-
*arthurnn*
|
398
|
-
|
399
|
-
* PostgreSQL invalid `uuid` are convert to nil.
|
400
|
-
|
401
|
-
*Abdelkader Boudih*
|
402
|
-
|
403
|
-
* Restore 4.0 behavior for using serialize attributes with `JSON` as coder.
|
404
|
-
|
405
|
-
With 4.1.x, `serialize` started returning a string when `JSON` was passed as
|
406
|
-
the second attribute. It will now return a hash as per previous versions.
|
407
|
-
|
408
|
-
Example:
|
409
|
-
|
410
|
-
class Post < ActiveRecord::Base
|
411
|
-
serialize :comment, JSON
|
412
|
-
end
|
413
|
-
|
414
|
-
class Comment
|
415
|
-
include ActiveModel::Model
|
416
|
-
attr_accessor :category, :text
|
417
|
-
end
|
133
|
+
*Ryuta Kamzono*
|
418
134
|
|
419
|
-
|
420
|
-
|
421
|
-
post.save!
|
135
|
+
* `change_column_comment` and `change_table_comment` are invertible only if
|
136
|
+
`to` and `from` options are specified.
|
422
137
|
|
423
|
-
|
424
|
-
post.comment # => {"category"=>"Animals", "text"=>"This is a comment about squirrels."}
|
138
|
+
*Yoshiyuki Kinjo*
|
425
139
|
|
426
|
-
|
427
|
-
post.comment # => "#<Comment:0x007f80ab48ff98>"
|
140
|
+
* Don't call commit/rollback callbacks when a record isn't saved.
|
428
141
|
|
429
|
-
|
430
|
-
post.comment # => {"category"=>"Animals", "text"=>"This is a comment about squirrels."}
|
142
|
+
Fixes #29747.
|
431
143
|
|
432
|
-
|
433
|
-
new `ActiveRecord::Coders::JSON` coder which delegates its `dump/load` to
|
434
|
-
`ActiveSupport::JSON.encode/decode`. This ensures special objects are dumped
|
435
|
-
correctly using the `#as_json` hook.
|
436
|
-
|
437
|
-
To keep the previous behaviour, supply a custom coder instead
|
438
|
-
([example](https://gist.github.com/jenncoop/8c4142bbe59da77daa63)).
|
439
|
-
|
440
|
-
Fixes #15594.
|
441
|
-
|
442
|
-
*Jenn Cooper*
|
443
|
-
|
444
|
-
* Do not use `RENAME INDEX` syntax for MariaDB 10.0.
|
445
|
-
|
446
|
-
Fixes #15931.
|
447
|
-
|
448
|
-
*Jeff Browning*
|
449
|
-
|
450
|
-
* Calling `#empty?` on a `has_many` association would use the value from the
|
451
|
-
counter cache if one exists.
|
144
|
+
*Ryuta Kamizono*
|
452
145
|
|
453
|
-
|
146
|
+
* Fix circular `autosave: true` causes invalid records to be saved.
|
454
147
|
|
455
|
-
|
456
|
-
|
148
|
+
Prior to the fix, when there was a circular series of `autosave: true`
|
149
|
+
associations, the callback for a `has_many` association was run while
|
150
|
+
another instance of the same callback on the same association hadn't
|
151
|
+
finished running. When control returned to the first instance of the
|
152
|
+
callback, the instance variable had changed, and subsequent associated
|
153
|
+
records weren't saved correctly. Specifically, the ID field for the
|
154
|
+
`belongs_to` corresponding to the `has_many` was `nil`.
|
457
155
|
|
458
|
-
Fixes #
|
156
|
+
Fixes #28080.
|
459
157
|
|
460
|
-
*
|
158
|
+
*Larry Reid*
|
461
159
|
|
462
|
-
*
|
463
|
-
produce an `IN` statements.
|
160
|
+
* Raise `ArgumentError` for invalid `:limit` and `:precision` like as other options.
|
464
161
|
|
465
162
|
Before:
|
466
163
|
|
467
|
-
|
468
|
-
|
164
|
+
```ruby
|
165
|
+
add_column :items, :attr1, :binary, size: 10 # => ArgumentError
|
166
|
+
add_column :items, :attr2, :decimal, scale: 10 # => ArgumentError
|
167
|
+
add_column :items, :attr3, :integer, limit: 10 # => ActiveRecordError
|
168
|
+
add_column :items, :attr4, :datetime, precision: 10 # => ActiveRecordError
|
169
|
+
```
|
469
170
|
|
470
171
|
After:
|
471
172
|
|
472
|
-
|
473
|
-
|
474
|
-
|
475
|
-
|
476
|
-
|
477
|
-
|
478
|
-
values for string columns. Otherwise, in some database, the string column
|
479
|
-
values will be coerced to a numeric allowing false or 0.seconds match any
|
480
|
-
string starting with a non-digit.
|
481
|
-
|
482
|
-
Example:
|
483
|
-
|
484
|
-
App.where(apikey: false) # => SELECT * FROM users WHERE apikey = '0'
|
485
|
-
|
486
|
-
*Dylan Thacker-Smith*
|
487
|
-
|
488
|
-
* Add a `:required` option to singular associations, providing a nicer
|
489
|
-
API for presence validations on associations.
|
490
|
-
|
491
|
-
*Sean Griffin*
|
492
|
-
|
493
|
-
* Fix an error in `reset_counters` when associations have `select` scope.
|
494
|
-
(Call to `count` generated invalid SQL.)
|
173
|
+
```ruby
|
174
|
+
add_column :items, :attr1, :binary, size: 10 # => ArgumentError
|
175
|
+
add_column :items, :attr2, :decimal, scale: 10 # => ArgumentError
|
176
|
+
add_column :items, :attr3, :integer, limit: 10 # => ArgumentError
|
177
|
+
add_column :items, :attr4, :datetime, precision: 10 # => ArgumentError
|
178
|
+
```
|
495
179
|
|
496
|
-
*
|
497
|
-
|
498
|
-
* After a successful `reload`, `new_record?` is always false.
|
499
|
-
|
500
|
-
Fixes #12101.
|
501
|
-
|
502
|
-
*Matthew Draper*
|
503
|
-
|
504
|
-
* PostgreSQL renaming table doesn't attempt to rename non existent sequences.
|
505
|
-
|
506
|
-
*Abdelkader Boudih*
|
507
|
-
|
508
|
-
* Move 'dependent: :destroy' handling for `belongs_to`
|
509
|
-
from `before_destroy` to `after_destroy` callback chain
|
510
|
-
|
511
|
-
Fixes #12380.
|
512
|
-
|
513
|
-
*Ivan Antropov*
|
514
|
-
|
515
|
-
* Detect in-place modifications on String attributes.
|
180
|
+
*Ryuta Kamizono*
|
516
181
|
|
517
|
-
|
518
|
-
|
519
|
-
required.
|
182
|
+
* Association loading isn't to be affected by scoping consistently
|
183
|
+
whether preloaded / eager loaded or not, with the exception of `unscoped`.
|
520
184
|
|
521
185
|
Before:
|
522
186
|
|
523
|
-
|
524
|
-
|
525
|
-
|
526
|
-
|
527
|
-
|
187
|
+
```ruby
|
188
|
+
Post.where("1=0").scoping do
|
189
|
+
Comment.find(1).post # => nil
|
190
|
+
Comment.preload(:post).find(1).post # => #<Post id: 1, ...>
|
191
|
+
Comment.eager_load(:post).find(1).post # => #<Post id: 1, ...>
|
192
|
+
end
|
193
|
+
```
|
528
194
|
|
529
195
|
After:
|
530
196
|
|
531
|
-
|
532
|
-
|
533
|
-
|
534
|
-
|
535
|
-
|
536
|
-
|
537
|
-
|
538
|
-
* Add `ActiveRecord::Base#validate!` that raises `RecordInvalid` if the record
|
539
|
-
is invalid.
|
197
|
+
```ruby
|
198
|
+
Post.where("1=0").scoping do
|
199
|
+
Comment.find(1).post # => #<Post id: 1, ...>
|
200
|
+
Comment.preload(:post).find(1).post # => #<Post id: 1, ...>
|
201
|
+
Comment.eager_load(:post).find(1).post # => #<Post id: 1, ...>
|
202
|
+
end
|
203
|
+
```
|
540
204
|
|
541
|
-
|
542
|
-
|
543
|
-
* Support for adding and removing foreign keys. Foreign keys are now
|
544
|
-
a part of `schema.rb`. This is supported by Mysql2Adapter, MysqlAdapter
|
545
|
-
and PostgreSQLAdapter.
|
546
|
-
|
547
|
-
Many thanks to *Matthew Higgins* for laying the foundation with his work on
|
548
|
-
[foreigner](https://github.com/matthuhiggins/foreigner).
|
549
|
-
|
550
|
-
Example:
|
205
|
+
Fixes #34638, #35398.
|
551
206
|
|
552
|
-
|
553
|
-
add_foreign_key :articles, :authors
|
554
|
-
remove_foreign_key :articles, :authors
|
555
|
-
|
556
|
-
*Yves Senn*
|
557
|
-
|
558
|
-
* Fix subtle bugs regarding attribute assignment on models with no primary
|
559
|
-
key. `'id'` will no longer be part of the attributes hash.
|
560
|
-
|
561
|
-
*Sean Griffin*
|
562
|
-
|
563
|
-
* Deprecate automatic counter caches on `has_many :through`. The behavior was
|
564
|
-
broken and inconsistent.
|
565
|
-
|
566
|
-
*Sean Griffin*
|
567
|
-
|
568
|
-
* `preload` preserves readonly flag for associations.
|
569
|
-
|
570
|
-
See #15853.
|
571
|
-
|
572
|
-
*Yves Senn*
|
573
|
-
|
574
|
-
* Assume numeric types have changed if they were assigned to a value that
|
575
|
-
would fail numericality validation, regardless of the old value. Previously
|
576
|
-
this would only occur if the old value was 0.
|
577
|
-
|
578
|
-
Example:
|
579
|
-
|
580
|
-
model = Model.create!(number: 5)
|
581
|
-
model.number = '5wibble'
|
582
|
-
model.number_changed? # => true
|
583
|
-
|
584
|
-
Fixes #14731.
|
585
|
-
|
586
|
-
*Sean Griffin*
|
207
|
+
*Ryuta Kamizono*
|
587
208
|
|
588
|
-
* `
|
589
|
-
The attribute hash is fully replaced. The record is put into the same state
|
590
|
-
as it would be with `Model.find(model.id)`.
|
209
|
+
* Add `rails db:prepare` to migrate or setup a database.
|
591
210
|
|
592
|
-
|
211
|
+
Runs `db:migrate` if the database exists or `db:setup` if it doesn't.
|
593
212
|
|
594
|
-
*
|
595
|
-
If this is not the case a `NoMethodError` is raised.
|
213
|
+
*Roberto Miranda*
|
596
214
|
|
597
|
-
|
215
|
+
* Add `after_save_commit` callback as shortcut for `after_commit :hook, on: [ :create, :update ]`.
|
598
216
|
|
599
|
-
*
|
217
|
+
*DHH*
|
600
218
|
|
601
|
-
|
219
|
+
* Assign all attributes before calling `build` to ensure the child record is visible in
|
220
|
+
`before_add` and `after_add` callbacks for `has_many :through` associations.
|
602
221
|
|
603
|
-
|
222
|
+
Fixes #33249.
|
604
223
|
|
605
|
-
*
|
224
|
+
*Ryan H. Kerr*
|
606
225
|
|
607
|
-
*
|
226
|
+
* Add `ActiveRecord::Relation#extract_associated` for extracting associated records from a relation.
|
608
227
|
|
609
|
-
|
228
|
+
```
|
229
|
+
account.memberships.extract_associated(:user)
|
230
|
+
# => Returns collection of User records
|
231
|
+
```
|
610
232
|
|
611
|
-
*
|
612
|
-
are part of the URI structure, not the actual host.
|
233
|
+
*DHH*
|
613
234
|
|
614
|
-
|
235
|
+
* Add `ActiveRecord::Relation#annotate` for adding SQL comments to its queries.
|
615
236
|
|
616
|
-
|
237
|
+
For example:
|
617
238
|
|
618
|
-
|
619
|
-
|
239
|
+
```
|
240
|
+
Post.where(id: 123).annotate("this is a comment").to_sql
|
241
|
+
# SELECT "posts".* FROM "posts" WHERE "posts"."id" = 123 /* this is a comment */
|
242
|
+
```
|
620
243
|
|
621
|
-
|
244
|
+
This can be useful in instrumentation or other analysis of issued queries.
|
622
245
|
|
623
|
-
*
|
624
|
-
Serialized attributes on ActiveRecord models will no longer save when
|
625
|
-
unchanged.
|
246
|
+
*Matt Yoho*
|
626
247
|
|
627
|
-
|
248
|
+
* Support Optimizer Hints.
|
628
249
|
|
629
|
-
|
250
|
+
In most databases, a way to control the optimizer is by using optimizer hints,
|
251
|
+
which can be specified within individual statements.
|
630
252
|
|
631
|
-
|
632
|
-
name.
|
253
|
+
Example (for MySQL):
|
633
254
|
|
634
|
-
|
255
|
+
Topic.optimizer_hints("MAX_EXECUTION_TIME(50000)", "NO_INDEX_MERGE(topics)")
|
256
|
+
# SELECT /*+ MAX_EXECUTION_TIME(50000) NO_INDEX_MERGE(topics) */ `topics`.* FROM `topics`
|
635
257
|
|
636
|
-
|
258
|
+
Example (for PostgreSQL with pg_hint_plan):
|
637
259
|
|
638
|
-
|
260
|
+
Topic.optimizer_hints("SeqScan(topics)", "Parallel(topics 8)")
|
261
|
+
# SELECT /*+ SeqScan(topics) Parallel(topics 8) */ "topics".* FROM "topics"
|
639
262
|
|
640
|
-
|
263
|
+
See also:
|
641
264
|
|
642
|
-
*
|
265
|
+
* https://dev.mysql.com/doc/refman/8.0/en/optimizer-hints.html
|
266
|
+
* https://pghintplan.osdn.jp/pg_hint_plan.html
|
267
|
+
* https://docs.oracle.com/en/database/oracle/oracle-database/12.2/tgsql/influencing-the-optimizer.html
|
268
|
+
* https://docs.microsoft.com/en-us/sql/t-sql/queries/hints-transact-sql-query?view=sql-server-2017
|
269
|
+
* https://www.ibm.com/support/knowledgecenter/en/SSEPGG_11.1.0/com.ibm.db2.luw.admin.perf.doc/doc/c0070117.html
|
643
270
|
|
644
|
-
*
|
645
|
-
|
646
|
-
* `ActiveRecord::FinderMethods.find` with block can handle proc parameter as
|
647
|
-
`Enumerable#find` does.
|
648
|
-
|
649
|
-
Fixes #15382.
|
271
|
+
*Ryuta Kamizono*
|
650
272
|
|
651
|
-
|
273
|
+
* Fix query attribute method on user-defined attribute to be aware of typecasted value.
|
652
274
|
|
653
|
-
|
275
|
+
For example, the following code no longer return false as casted non-empty string:
|
654
276
|
|
655
|
-
|
277
|
+
```
|
278
|
+
class Post < ActiveRecord::Base
|
279
|
+
attribute :user_defined_text, :text
|
280
|
+
end
|
656
281
|
|
657
|
-
|
282
|
+
Post.new(user_defined_text: "false").user_defined_text? # => true
|
283
|
+
```
|
658
284
|
|
659
|
-
*
|
660
|
-
`primary_key_prefix_type` configuration.
|
285
|
+
*Yuji Kamijima*
|
661
286
|
|
662
|
-
|
287
|
+
* Quote empty ranges like other empty enumerables.
|
663
288
|
|
664
|
-
*
|
289
|
+
*Patrick Rebsch*
|
665
290
|
|
666
|
-
*
|
291
|
+
* Add `insert_all`/`insert_all!`/`upsert_all` methods to `ActiveRecord::Persistence`,
|
292
|
+
allowing bulk inserts akin to the bulk updates provided by `update_all` and
|
293
|
+
bulk deletes by `delete_all`.
|
667
294
|
|
668
|
-
|
295
|
+
Supports skipping or upserting duplicates through the `ON CONFLICT` syntax
|
296
|
+
for PostgreSQL (9.5+) and SQLite (3.24+) and `ON DUPLICATE KEY UPDATE` syntax
|
297
|
+
for MySQL.
|
669
298
|
|
670
|
-
*
|
299
|
+
*Bob Lail*
|
671
300
|
|
672
|
-
*
|
301
|
+
* Add `rails db:seed:replant` that truncates tables of each database
|
302
|
+
for current environment and loads the seeds.
|
673
303
|
|
674
|
-
|
675
|
-
updated.
|
304
|
+
*bogdanvlviv*, *DHH*
|
676
305
|
|
677
|
-
|
306
|
+
* Add `ActiveRecord::Base.connection.truncate` for SQLite3 adapter.
|
678
307
|
|
679
|
-
*
|
308
|
+
*bogdanvlviv*
|
680
309
|
|
681
|
-
*
|
682
|
-
`proper_table_name` instance method on `ActiveRecord::Migration` instead.
|
310
|
+
* Deprecate mismatched collation comparison for uniqueness validator.
|
683
311
|
|
684
|
-
|
312
|
+
Uniqueness validator will no longer enforce case sensitive comparison in Rails 6.1.
|
313
|
+
To continue case sensitive comparison on the case insensitive column,
|
314
|
+
pass `case_sensitive: true` option explicitly to the uniqueness validator.
|
685
315
|
|
686
|
-
*
|
687
|
-
existing column.
|
316
|
+
*Ryuta Kamizono*
|
688
317
|
|
689
|
-
|
318
|
+
* Add `reselect` method. This is a short-hand for `unscope(:select).select(fields)`.
|
690
319
|
|
691
|
-
|
320
|
+
Fixes #27340.
|
692
321
|
|
693
|
-
*
|
694
|
-
It will return a null object in Rails 5.0
|
322
|
+
*Willian Gustavo Veiga*
|
695
323
|
|
696
|
-
|
324
|
+
* Add negative scopes for all enum values.
|
697
325
|
|
698
|
-
|
326
|
+
Example:
|
699
327
|
|
700
|
-
|
328
|
+
class Post < ActiveRecord::Base
|
329
|
+
enum status: %i[ drafted active trashed ]
|
330
|
+
end
|
701
331
|
|
702
|
-
|
703
|
-
|
332
|
+
Post.not_drafted # => where.not(status: :drafted)
|
333
|
+
Post.not_active # => where.not(status: :active)
|
334
|
+
Post.not_trashed # => where.not(status: :trashed)
|
704
335
|
|
705
|
-
*
|
336
|
+
*DHH*
|
706
337
|
|
707
|
-
*
|
338
|
+
* Fix different `count` calculation when using `size` with manual `select` with DISTINCT.
|
708
339
|
|
709
|
-
|
340
|
+
Fixes #35214.
|
710
341
|
|
711
|
-
*
|
342
|
+
*Juani Villarejo*
|
712
343
|
|
713
|
-
*Yves Senn*
|
714
344
|
|
715
|
-
|
345
|
+
## Rails 6.0.0.beta3 (March 11, 2019) ##
|
716
346
|
|
717
|
-
|
347
|
+
* No changes.
|
718
348
|
|
719
|
-
* Fix `columns_for_distinct` of PostgreSQL adapter to work correctly
|
720
|
-
with orders without sort direction modifiers.
|
721
349
|
|
722
|
-
|
350
|
+
## Rails 6.0.0.beta2 (February 25, 2019) ##
|
723
351
|
|
724
|
-
*
|
352
|
+
* Fix prepared statements caching to be enabled even when query caching is enabled.
|
725
353
|
|
726
|
-
*
|
354
|
+
*Ryuta Kamizono*
|
727
355
|
|
728
|
-
*
|
729
|
-
Fixes duplication in combination with `store_accessor`.
|
356
|
+
* Ensure `update_all` series cares about optimistic locking.
|
730
357
|
|
731
|
-
|
358
|
+
*Ryuta Kamizono*
|
732
359
|
|
733
|
-
|
360
|
+
* Don't allow `where` with non numeric string matches to 0 values.
|
734
361
|
|
735
|
-
*
|
362
|
+
*Ryuta Kamizono*
|
736
363
|
|
737
|
-
|
364
|
+
* Introduce `ActiveRecord::Relation#destroy_by` and `ActiveRecord::Relation#delete_by`.
|
738
365
|
|
739
|
-
|
740
|
-
|
741
|
-
definition into a subclass would raise.
|
366
|
+
`destroy_by` allows relation to find all the records matching the condition and perform
|
367
|
+
`destroy_all` on the matched records.
|
742
368
|
|
743
|
-
|
369
|
+
Example:
|
744
370
|
|
745
|
-
|
371
|
+
Person.destroy_by(name: 'David')
|
372
|
+
Person.destroy_by(name: 'David', rating: 4)
|
746
373
|
|
747
|
-
|
748
|
-
|
749
|
-
But as `reflections` is a public API, people expect to see the right macro.
|
374
|
+
david = Person.find_by(name: 'David')
|
375
|
+
david.posts.destroy_by(id: [1, 2, 3])
|
750
376
|
|
751
|
-
|
377
|
+
`delete_by` allows relation to find all the records matching the condition and perform
|
378
|
+
`delete_all` on the matched records.
|
752
379
|
|
753
|
-
|
380
|
+
Example:
|
754
381
|
|
755
|
-
|
382
|
+
Person.delete_by(name: 'David')
|
383
|
+
Person.delete_by(name: 'David', rating: 4)
|
756
384
|
|
757
|
-
|
385
|
+
david = Person.find_by(name: 'David')
|
386
|
+
david.posts.delete_by(id: [1, 2, 3])
|
758
387
|
|
759
|
-
*
|
388
|
+
*Abhay Nikam*
|
760
389
|
|
761
|
-
*
|
762
|
-
on a NullRelation should return a Hash.
|
390
|
+
* Don't allow `where` with invalid value matches to nil values.
|
763
391
|
|
764
|
-
|
392
|
+
Fixes #33624.
|
765
393
|
|
766
|
-
*
|
767
|
-
`update_column`.
|
394
|
+
*Ryuta Kamizono*
|
768
395
|
|
769
|
-
|
396
|
+
* SQLite3: Implement `add_foreign_key` and `remove_foreign_key`.
|
770
397
|
|
771
|
-
*
|
398
|
+
*Ryuta Kamizono*
|
772
399
|
|
773
|
-
|
400
|
+
* Deprecate using class level querying methods if the receiver scope
|
401
|
+
regarded as leaked. Use `klass.unscoped` to avoid the leaking scope.
|
774
402
|
|
775
|
-
*
|
403
|
+
*Ryuta Kamizono*
|
776
404
|
|
777
|
-
*
|
405
|
+
* Allow applications to automatically switch connections.
|
778
406
|
|
779
|
-
|
780
|
-
|
781
|
-
|
407
|
+
Adds a middleware and configuration options that can be used in your
|
408
|
+
application to automatically switch between the writing and reading
|
409
|
+
database connections.
|
782
410
|
|
783
|
-
|
411
|
+
`GET` and `HEAD` requests will read from the replica unless there was
|
412
|
+
a write in the last 2 seconds, otherwise they will read from the primary.
|
413
|
+
Non-get requests will always write to the primary. The middleware accepts
|
414
|
+
an argument for a Resolver class and an Operations class where you are able
|
415
|
+
to change how the auto-switcher works to be most beneficial for your
|
416
|
+
application.
|
784
417
|
|
785
|
-
|
786
|
-
|
418
|
+
To use the middleware in your application you can use the following
|
419
|
+
configuration options:
|
787
420
|
|
788
|
-
|
421
|
+
```
|
422
|
+
config.active_record.database_selector = { delay: 2.seconds }
|
423
|
+
config.active_record.database_resolver = ActiveRecord::Middleware::DatabaseSelector::Resolver
|
424
|
+
config.active_record.database_resolver_context = ActiveRecord::Middleware::DatabaseSelector::Resolver::Session
|
425
|
+
```
|
789
426
|
|
790
|
-
|
427
|
+
To change the database selection strategy, pass a custom class to the
|
428
|
+
configuration options:
|
791
429
|
|
792
|
-
|
793
|
-
|
794
|
-
|
430
|
+
```
|
431
|
+
config.active_record.database_selector = { delay: 10.seconds }
|
432
|
+
config.active_record.database_resolver = MyResolver
|
433
|
+
config.active_record.database_resolver_context = MyResolver::MyCookies
|
434
|
+
```
|
795
435
|
|
796
|
-
*
|
436
|
+
*Eileen M. Uchitelle*
|
797
437
|
|
798
|
-
*
|
799
|
-
extension names in PostgreSQL when migrating.
|
438
|
+
* MySQL: Support `:size` option to change text and blob size.
|
800
439
|
|
801
|
-
*
|
440
|
+
*Ryuta Kamizono*
|
802
441
|
|
803
|
-
*
|
804
|
-
`references`, now works with any column types.
|
442
|
+
* Make `t.timestamps` with precision by default.
|
805
443
|
|
806
|
-
*
|
444
|
+
*Ryuta Kamizono*
|
807
445
|
|
808
|
-
* Add support for counter name to be passed as parameter on `CounterCache::ClassMethods#reset_counters`.
|
809
446
|
|
810
|
-
|
447
|
+
## Rails 6.0.0.beta1 (January 18, 2019) ##
|
811
448
|
|
812
|
-
*
|
813
|
-
or `offset`.
|
449
|
+
* Remove deprecated `#set_state` from the transaction object.
|
814
450
|
|
815
|
-
|
816
|
-
records to be deleted.
|
451
|
+
*Rafael Mendonça França*
|
817
452
|
|
818
|
-
|
453
|
+
* Remove deprecated `#supports_statement_cache?` from the database adapters.
|
819
454
|
|
820
|
-
*
|
455
|
+
*Rafael Mendonça França*
|
821
456
|
|
822
|
-
*
|
823
|
-
their limit dropped from the schema.
|
457
|
+
* Remove deprecated `#insert_fixtures` from the database adapters.
|
824
458
|
|
825
|
-
|
459
|
+
*Rafael Mendonça França*
|
826
460
|
|
827
|
-
|
461
|
+
* Remove deprecated `ActiveRecord::ConnectionAdapters::SQLite3Adapter#valid_alter_table_type?`.
|
828
462
|
|
829
|
-
*
|
830
|
-
association.
|
463
|
+
*Rafael Mendonça França*
|
831
464
|
|
832
|
-
|
465
|
+
* Do not allow passing the column name to `sum` when a block is passed.
|
833
466
|
|
834
|
-
*
|
467
|
+
*Rafael Mendonça França*
|
835
468
|
|
836
|
-
* `
|
837
|
-
strings in column names as equal.
|
469
|
+
* Do not allow passing the column name to `count` when a block is passed.
|
838
470
|
|
839
|
-
|
840
|
-
placeholders for them in the generated SQL statement, which can make PostgreSQL
|
841
|
-
throw a `StatementInvalid` exception.
|
471
|
+
*Rafael Mendonça França*
|
842
472
|
|
843
|
-
|
473
|
+
* Remove delegation of missing methods in a relation to arel.
|
844
474
|
|
845
|
-
*
|
846
|
-
attributes defined in parent classes.
|
475
|
+
*Rafael Mendonça França*
|
847
476
|
|
848
|
-
|
477
|
+
* Remove delegation of missing methods in a relation to private methods of the class.
|
849
478
|
|
850
|
-
*
|
479
|
+
*Rafael Mendonça França*
|
851
480
|
|
852
|
-
*
|
481
|
+
* Deprecate `config.activerecord.sqlite3.represent_boolean_as_integer`.
|
853
482
|
|
854
|
-
|
483
|
+
*Rafael Mendonça França*
|
855
484
|
|
856
|
-
|
485
|
+
* Change `SQLite3Adapter` to always represent boolean values as integers.
|
857
486
|
|
858
|
-
*
|
487
|
+
*Rafael Mendonça França*
|
859
488
|
|
860
|
-
|
861
|
-
PostgreSQL and are used by internal system catalogs. These field types
|
862
|
-
can sometimes show up in structure-sniffing queries that feature internal system
|
863
|
-
structures or with certain PostgreSQL extensions.
|
489
|
+
* Remove ability to specify a timestamp name for `#cache_key`.
|
864
490
|
|
865
|
-
*
|
491
|
+
*Rafael Mendonça França*
|
866
492
|
|
867
|
-
*
|
868
|
-
NaN PostgreSQL values into a native Ruby `Float::INFINITY` and `Float::NAN`
|
493
|
+
* Remove deprecated `ActiveRecord::Migrator.migrations_path=`.
|
869
494
|
|
870
|
-
|
495
|
+
*Rafael Mendonça França*
|
871
496
|
|
872
|
-
|
873
|
-
Point.last.value # => 0.0
|
497
|
+
* Remove deprecated `expand_hash_conditions_for_aggregates`.
|
874
498
|
|
875
|
-
|
499
|
+
*Rafael Mendonça França*
|
876
500
|
|
877
|
-
|
878
|
-
Point.last.value # => Infinity
|
501
|
+
* Set polymorphic type column to NULL on `dependent: :nullify` strategy.
|
879
502
|
|
880
|
-
|
503
|
+
On polymorphic associations both the foreign key and the foreign type columns will be set to NULL.
|
881
504
|
|
882
|
-
*
|
505
|
+
*Laerti Papa*
|
883
506
|
|
884
|
-
|
507
|
+
* Allow permitted instance of `ActionController::Parameters` as argument of `ActiveRecord::Relation#exists?`.
|
885
508
|
|
886
|
-
*
|
509
|
+
*Gannon McGibbon*
|
887
510
|
|
888
|
-
*
|
889
|
-
associations without replacement. These operations happen before instances
|
890
|
-
are created. The current behavior is unexpected and can result in broken
|
891
|
-
behavior.
|
511
|
+
* Add support for endless ranges introduces in Ruby 2.6.
|
892
512
|
|
893
|
-
|
513
|
+
*Greg Navis*
|
894
514
|
|
895
|
-
|
515
|
+
* Deprecate passing `migrations_paths` to `connection.assume_migrated_upto_version`.
|
896
516
|
|
897
|
-
*
|
517
|
+
*Ryuta Kamizono*
|
898
518
|
|
899
|
-
|
900
|
-
size calculation if the collection is not cached or loaded.
|
519
|
+
* MySQL: `ROW_FORMAT=DYNAMIC` create table option by default.
|
901
520
|
|
902
|
-
|
521
|
+
Since MySQL 5.7.9, the `innodb_default_row_format` option defines the default row
|
522
|
+
format for InnoDB tables. The default setting is `DYNAMIC`.
|
523
|
+
The row format is required for indexing on `varchar(255)` with `utf8mb4` columns.
|
903
524
|
|
904
|
-
*
|
525
|
+
*Ryuta Kamizono*
|
905
526
|
|
906
|
-
*
|
907
|
-
not exist.
|
527
|
+
* Fix join table column quoting with SQLite.
|
908
528
|
|
909
|
-
*
|
529
|
+
*Gannon McGibbon*
|
910
530
|
|
911
|
-
*
|
531
|
+
* Allow disabling scopes generated by `ActiveRecord.enum`.
|
912
532
|
|
913
|
-
|
914
|
-
using namespaced models.
|
533
|
+
*Alfred Dominic*
|
915
534
|
|
916
|
-
|
535
|
+
* Ensure that `delete_all` on collection proxy returns affected count.
|
917
536
|
|
918
|
-
*
|
537
|
+
*Ryuta Kamizono*
|
919
538
|
|
920
|
-
|
921
|
-
In 4.0 series it is delegated to `Array#join`.
|
539
|
+
* Reset scope after delete on collection association to clear stale offsets of removed records.
|
922
540
|
|
923
|
-
*
|
541
|
+
*Gannon McGibbon*
|
924
542
|
|
925
|
-
*
|
543
|
+
* Add the ability to prevent writes to a database for the duration of a block.
|
926
544
|
|
927
|
-
|
928
|
-
|
929
|
-
|
930
|
-
that already has a non-nil value in that column since an initial nil
|
931
|
-
value isn't included in the SQL anyway (at least, when dirty checking
|
932
|
-
is enabled.) The column's new value will now be logged as `<NULL binary data>`
|
933
|
-
to parallel the existing `<N bytes of binary data>` for non-nil values.
|
545
|
+
Allows the application to prevent writes to a database. This can be useful when
|
546
|
+
you're building out multiple databases and want to make sure you're not sending
|
547
|
+
writes when you want a read.
|
934
548
|
|
935
|
-
|
549
|
+
If `while_preventing_writes` is called and the query is considered a write
|
550
|
+
query the database will raise an exception regardless of whether the database
|
551
|
+
user is able to write.
|
936
552
|
|
937
|
-
|
938
|
-
|
553
|
+
This is not meant to be a catch-all for write queries but rather a way to enforce
|
554
|
+
read-only queries without opening a second connection. One purpose of this is to
|
555
|
+
catch accidental writes, not all writes.
|
939
556
|
|
940
|
-
|
557
|
+
*Eileen M. Uchitelle*
|
941
558
|
|
942
|
-
|
559
|
+
* Allow aliased attributes to be used in `#update_columns` and `#update`.
|
943
560
|
|
944
|
-
*
|
561
|
+
*Gannon McGibbon*
|
945
562
|
|
946
|
-
|
947
|
-
was ignored and overwritten by strict mode option.
|
563
|
+
* Allow spaces in postgres table names.
|
948
564
|
|
949
|
-
Fixes
|
565
|
+
Fixes issue where "user post" is misinterpreted as "\"user\".\"post\"" when quoting table names with the postgres adapter.
|
950
566
|
|
951
|
-
*
|
567
|
+
*Gannon McGibbon*
|
952
568
|
|
953
|
-
*
|
569
|
+
* Cached `columns_hash` fields should be excluded from `ResultSet#column_types`.
|
954
570
|
|
955
|
-
|
571
|
+
PR #34528 addresses the inconsistent behaviour when attribute is defined for an ignored column. The following test
|
572
|
+
was passing for SQLite and MySQL, but failed for PostgreSQL:
|
956
573
|
|
957
|
-
|
574
|
+
```ruby
|
575
|
+
class DeveloperName < ActiveRecord::Type::String
|
576
|
+
def deserialize(value)
|
577
|
+
"Developer: #{value}"
|
578
|
+
end
|
579
|
+
end
|
958
580
|
|
959
|
-
|
581
|
+
class AttributedDeveloper < ActiveRecord::Base
|
582
|
+
self.table_name = "developers"
|
960
583
|
|
961
|
-
|
584
|
+
attribute :name, DeveloperName.new
|
962
585
|
|
963
|
-
|
964
|
-
|
965
|
-
uses the reflections to set database with fixtures.
|
586
|
+
self.ignored_columns += ["name"]
|
587
|
+
end
|
966
588
|
|
967
|
-
|
589
|
+
developer = AttributedDeveloper.create
|
590
|
+
developer.update_column :name, "name"
|
968
591
|
|
969
|
-
|
592
|
+
loaded_developer = AttributedDeveloper.where(id: developer.id).select("*").first
|
593
|
+
puts loaded_developer.name # should be "Developer: name" but it's just "name"
|
594
|
+
```
|
970
595
|
|
971
|
-
*
|
972
|
-
Additionally display a warning message to make the user aware.
|
596
|
+
*Dmitry Tsepelev*
|
973
597
|
|
974
|
-
|
598
|
+
* Make the implicit order column configurable.
|
975
599
|
|
976
|
-
|
977
|
-
|
600
|
+
When calling ordered finder methods such as `first` or `last` without an
|
601
|
+
explicit order clause, ActiveRecord sorts records by primary key. This can
|
602
|
+
result in unpredictable and surprising behaviour when the primary key is
|
603
|
+
not an auto-incrementing integer, for example when it's a UUID. This change
|
604
|
+
makes it possible to override the column used for implicit ordering such
|
605
|
+
that `first` and `last` will return more predictable results.
|
978
606
|
|
979
607
|
Example:
|
980
608
|
|
981
|
-
|
982
|
-
|
983
|
-
|
984
|
-
# => also :datetime (previously would be :timestamp)
|
985
|
-
|
986
|
-
See #14513.
|
987
|
-
|
988
|
-
*Jefferson Lai*
|
989
|
-
|
990
|
-
* `ActiveRecord::Base.no_touching` no longer triggers callbacks or start empty transactions.
|
991
|
-
|
992
|
-
Fixes #14841.
|
993
|
-
|
994
|
-
*Lucas Mazza*
|
995
|
-
|
996
|
-
* Fix name collision with `Array#select!` with `Relation#select!`.
|
997
|
-
|
998
|
-
Fixes #14752.
|
999
|
-
|
1000
|
-
*Earl St Sauver*
|
609
|
+
class Project < ActiveRecord::Base
|
610
|
+
self.implicit_order_column = "created_at"
|
611
|
+
end
|
1001
612
|
|
1002
|
-
*
|
1003
|
-
a scoped `has_many`.
|
613
|
+
*Tekin Suleyman*
|
1004
614
|
|
1005
|
-
|
1006
|
-
`has_many :through` uses this association, then the scope adjustment is
|
1007
|
-
unexpectedly neglected.
|
615
|
+
* Bump minimum PostgreSQL version to 9.3.
|
1008
616
|
|
1009
|
-
|
617
|
+
*Yasuo Honda*
|
1010
618
|
|
1011
|
-
|
619
|
+
* Values of enum are frozen, raising an error when attempting to modify them.
|
1012
620
|
|
1013
|
-
*
|
621
|
+
*Emmanuel Byrd*
|
1014
622
|
|
1015
|
-
|
623
|
+
* Move `ActiveRecord::StatementInvalid` SQL to error property and include binds as separate error property.
|
1016
624
|
|
1017
|
-
|
625
|
+
`ActiveRecord::ConnectionAdapters::AbstractAdapter#translate_exception_class` now requires `binds` to be passed as the last argument.
|
1018
626
|
|
1019
|
-
|
627
|
+
`ActiveRecord::ConnectionAdapters::AbstractAdapter#translate_exception` now requires `message`, `sql`, and `binds` to be passed as keyword arguments.
|
1020
628
|
|
1021
|
-
|
629
|
+
Subclasses of `ActiveRecord::StatementInvalid` must now provide `sql:` and `binds:` arguments to `super`.
|
1022
630
|
|
1023
|
-
|
631
|
+
Example:
|
1024
632
|
|
1025
|
-
|
633
|
+
```
|
634
|
+
class MySubclassedError < ActiveRecord::StatementInvalid
|
635
|
+
def initialize(message, sql:, binds:)
|
636
|
+
super(message, sql: sql, binds: binds)
|
637
|
+
end
|
638
|
+
end
|
639
|
+
```
|
1026
640
|
|
1027
|
-
*
|
641
|
+
*Gannon McGibbon*
|
1028
642
|
|
1029
|
-
* `
|
1030
|
-
LIKE statement.
|
643
|
+
* Add an `:if_not_exists` option to `create_table`.
|
1031
644
|
|
1032
645
|
Example:
|
1033
646
|
|
1034
|
-
|
1035
|
-
|
1036
|
-
where("title LIKE ?", sanitize_sql_like(term))
|
1037
|
-
end
|
647
|
+
create_table :posts, if_not_exists: true do |t|
|
648
|
+
t.string :title
|
1038
649
|
end
|
1039
650
|
|
1040
|
-
|
1041
|
-
# => Query looks like "... title LIKE '20\% \_reduction\_' ..."
|
651
|
+
That would execute:
|
1042
652
|
|
1043
|
-
|
653
|
+
CREATE TABLE IF NOT EXISTS posts (
|
654
|
+
...
|
655
|
+
)
|
1044
656
|
|
1045
|
-
|
657
|
+
If the table already exists, `if_not_exists: false` (the default) raises an
|
658
|
+
exception whereas `if_not_exists: true` does nothing.
|
1046
659
|
|
1047
|
-
|
660
|
+
*fatkodima*, *Stefan Kanev*
|
1048
661
|
|
1049
|
-
|
662
|
+
* Defining an Enum as a Hash with blank key, or as an Array with a blank value, now raises an `ArgumentError`.
|
1050
663
|
|
1051
|
-
*
|
1052
|
-
|
1053
|
-
Example:
|
664
|
+
*Christophe Maximin*
|
1054
665
|
|
1055
|
-
|
1056
|
-
# => true
|
1057
|
-
Post.where(author_id: author.id) == author.posts
|
1058
|
-
# => true
|
666
|
+
* Adds support for multiple databases to `rails db:schema:cache:dump` and `rails db:schema:cache:clear`.
|
1059
667
|
|
1060
|
-
|
668
|
+
*Gannon McGibbon*
|
1061
669
|
|
1062
|
-
|
670
|
+
* `update_columns` now correctly raises `ActiveModel::MissingAttributeError`
|
671
|
+
if the attribute does not exist.
|
1063
672
|
|
1064
|
-
*
|
1065
|
-
generates an SQL statement containing each id of the collection:
|
1066
|
-
|
1067
|
-
Before:
|
1068
|
-
|
1069
|
-
DELETE FROM `model` WHERE `model`.`parent_id` = 1
|
1070
|
-
AND `model`.`id` IN (1, 2, 3...)
|
673
|
+
*Sean Griffin*
|
1071
674
|
|
1072
|
-
|
675
|
+
* Add support for hash and URL configs in database hash of `ActiveRecord::Base.connected_to`.
|
1073
676
|
|
1074
|
-
|
677
|
+
````
|
678
|
+
User.connected_to(database: { writing: "postgres://foo" }) do
|
679
|
+
User.create!(name: "Gannon")
|
680
|
+
end
|
1075
681
|
|
1076
|
-
|
682
|
+
config = { "adapter" => "sqlite3", "database" => "db/readonly.sqlite3" }
|
683
|
+
User.connected_to(database: { reading: config }) do
|
684
|
+
User.count
|
685
|
+
end
|
686
|
+
````
|
1077
687
|
|
1078
|
-
*
|
1079
|
-
with `select`.
|
688
|
+
*Gannon McGibbon*
|
1080
689
|
|
1081
|
-
|
690
|
+
* Support default expression for MySQL.
|
1082
691
|
|
1083
|
-
|
692
|
+
MySQL 8.0.13 and higher supports default value to be a function or expression.
|
1084
693
|
|
1085
|
-
|
694
|
+
https://dev.mysql.com/doc/refman/8.0/en/create-table.html
|
1086
695
|
|
1087
|
-
|
696
|
+
*Ryuta Kamizono*
|
1088
697
|
|
1089
|
-
|
698
|
+
* Support expression indexes for MySQL.
|
1090
699
|
|
1091
|
-
|
1092
|
-
|
700
|
+
MySQL 8.0.13 and higher supports functional key parts that index
|
701
|
+
expression values rather than column or column prefix values.
|
1093
702
|
|
1094
|
-
|
703
|
+
https://dev.mysql.com/doc/refman/8.0/en/create-index.html
|
1095
704
|
|
1096
|
-
*
|
705
|
+
*Ryuta Kamizono*
|
1097
706
|
|
1098
|
-
* Fix
|
707
|
+
* Fix collection cache key with limit and custom select to avoid ambiguous timestamp column error.
|
1099
708
|
|
1100
|
-
Fixes #
|
709
|
+
Fixes #33056.
|
1101
710
|
|
1102
|
-
*
|
711
|
+
*Federico Martinez*
|
1103
712
|
|
1104
|
-
*
|
713
|
+
* Add basic API for connection switching to support multiple databases.
|
1105
714
|
|
1106
|
-
|
715
|
+
1) Adds a `connects_to` method for models to connect to multiple databases. Example:
|
1107
716
|
|
1108
|
-
|
717
|
+
```
|
718
|
+
class AnimalsModel < ApplicationRecord
|
719
|
+
self.abstract_class = true
|
1109
720
|
|
1110
|
-
|
1111
|
-
|
721
|
+
connects_to database: { writing: :animals_primary, reading: :animals_replica }
|
722
|
+
end
|
1112
723
|
|
1113
|
-
|
724
|
+
class Dog < AnimalsModel
|
725
|
+
# connected to both the animals_primary db for writing and the animals_replica for reading
|
726
|
+
end
|
727
|
+
```
|
1114
728
|
|
1115
|
-
|
729
|
+
2) Adds a `connected_to` block method for switching connection roles or connecting to
|
730
|
+
a database that the model didn't connect to. Connecting to the database in this block is
|
731
|
+
useful when you have another defined connection, for example `slow_replica` that you don't
|
732
|
+
want to connect to by default but need in the console, or a specific code block.
|
1116
733
|
|
1117
|
-
|
734
|
+
```
|
735
|
+
ActiveRecord::Base.connected_to(role: :reading) do
|
736
|
+
Dog.first # finds dog from replica connected to AnimalsBase
|
737
|
+
Book.first # doesn't have a reading connection, will raise an error
|
738
|
+
end
|
739
|
+
```
|
1118
740
|
|
1119
|
-
|
741
|
+
```
|
742
|
+
ActiveRecord::Base.connected_to(database: :slow_replica) do
|
743
|
+
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
|
744
|
+
end
|
745
|
+
```
|
1120
746
|
|
1121
|
-
*
|
747
|
+
*Eileen M. Uchitelle*
|
1122
748
|
|
1123
|
-
*
|
749
|
+
* Enum raises on invalid definition values
|
1124
750
|
|
1125
|
-
|
751
|
+
When defining a Hash enum it can be easy to use `[]` instead of `{}`. This
|
752
|
+
commit checks that only valid definition values are provided, those can
|
753
|
+
be a Hash, an array of Symbols or an array of Strings. Otherwise it
|
754
|
+
raises an `ArgumentError`.
|
1126
755
|
|
1127
|
-
|
756
|
+
Fixes #33961
|
1128
757
|
|
1129
|
-
*
|
1130
|
-
could previously have incorrectly accrued additional conditions (e.g. as a result of
|
1131
|
-
a previous query). `CollectionProxy` now always defers to the association scope's
|
1132
|
-
`arel` method so the (incorrect) inherited one should be entirely concealed.
|
758
|
+
*Alberto Almagro*
|
1133
759
|
|
1134
|
-
|
760
|
+
* Reloading associations now clears the Query Cache like `Persistence#reload` does.
|
1135
761
|
|
1136
|
-
|
762
|
+
```
|
763
|
+
class Post < ActiveRecord::Base
|
764
|
+
has_one :category
|
765
|
+
belongs_to :author
|
766
|
+
has_many :comments
|
767
|
+
end
|
1137
768
|
|
1138
|
-
|
769
|
+
# Each of the following will now clear the query cache.
|
770
|
+
post.reload_category
|
771
|
+
post.reload_author
|
772
|
+
post.comments.reload
|
773
|
+
```
|
1139
774
|
|
1140
|
-
|
775
|
+
*Christophe Maximin*
|
1141
776
|
|
1142
|
-
|
777
|
+
* Added `index` option for `change_table` migration helpers.
|
778
|
+
With this change you can create indexes while adding new
|
779
|
+
columns into the existing tables.
|
1143
780
|
|
1144
|
-
|
781
|
+
Example:
|
1145
782
|
|
1146
|
-
|
783
|
+
change_table(:languages) do |t|
|
784
|
+
t.string :country_code, index: true
|
785
|
+
end
|
1147
786
|
|
1148
|
-
|
787
|
+
*Mehmet Emin İNAÇ*
|
1149
788
|
|
1150
|
-
|
789
|
+
* Fix `transaction` reverting for migrations.
|
1151
790
|
|
1152
|
-
|
1153
|
-
|
791
|
+
Before: Commands inside a `transaction` in a reverted migration ran uninverted.
|
792
|
+
Now: This change fixes that by reverting commands inside `transaction` block.
|
1154
793
|
|
1155
|
-
|
1156
|
-
`sqlite3:///my/path` with `sqlite3:my/path`.
|
794
|
+
*fatkodima*, *David Verhasselt*
|
1157
795
|
|
1158
|
-
|
796
|
+
* Raise an error instead of scanning the filesystem root when `fixture_path` is blank.
|
1159
797
|
|
1160
|
-
*
|
798
|
+
*Gannon McGibbon*, *Max Albrecht*
|
1161
799
|
|
1162
|
-
|
800
|
+
* Allow `ActiveRecord::Base.configurations=` to be set with a symbolized hash.
|
1163
801
|
|
1164
|
-
|
802
|
+
*Gannon McGibbon*
|
1165
803
|
|
1166
|
-
|
804
|
+
* Don't update counter cache unless the record is actually saved.
|
1167
805
|
|
1168
|
-
|
806
|
+
Fixes #31493, #33113, #33117.
|
1169
807
|
|
1170
|
-
*
|
808
|
+
*Ryuta Kamizono*
|
1171
809
|
|
1172
|
-
*
|
810
|
+
* Deprecate `ActiveRecord::Result#to_hash` in favor of `ActiveRecord::Result#to_a`.
|
1173
811
|
|
1174
|
-
*
|
812
|
+
*Gannon McGibbon*, *Kevin Cheng*
|
1175
813
|
|
1176
|
-
*
|
1177
|
-
The column types stay the same except for enum columns. They no longer have
|
1178
|
-
`nil` as type but `enum`.
|
814
|
+
* SQLite3 adapter supports expression indexes.
|
1179
815
|
|
1180
|
-
|
816
|
+
```
|
817
|
+
create_table :users do |t|
|
818
|
+
t.string :email
|
819
|
+
end
|
1181
820
|
|
1182
|
-
|
821
|
+
add_index :users, 'lower(email)', name: 'index_users_on_email', unique: true
|
822
|
+
```
|
1183
823
|
|
1184
|
-
*
|
1185
|
-
column.
|
824
|
+
*Gray Kemmey*
|
1186
825
|
|
1187
|
-
|
826
|
+
* Allow subclasses to redefine autosave callbacks for associated records.
|
1188
827
|
|
1189
|
-
|
828
|
+
Fixes #33305.
|
1190
829
|
|
1191
|
-
*
|
1192
|
-
custom primary key that did not save due to validation error.
|
830
|
+
*Andrey Subbota*
|
1193
831
|
|
1194
|
-
|
832
|
+
* Bump minimum MySQL version to 5.5.8.
|
1195
833
|
|
1196
|
-
*
|
834
|
+
*Yasuo Honda*
|
1197
835
|
|
1198
|
-
*
|
836
|
+
* Use MySQL utf8mb4 character set by default.
|
1199
837
|
|
1200
|
-
|
838
|
+
`utf8mb4` character set with 4-Byte encoding supports supplementary characters including emoji.
|
839
|
+
The previous default 3-Byte encoding character set `utf8` is not enough to support them.
|
1201
840
|
|
1202
|
-
*
|
841
|
+
*Yasuo Honda*
|
1203
842
|
|
1204
|
-
*
|
843
|
+
* Fix duplicated record creation when using nested attributes with `create_with`.
|
1205
844
|
|
1206
|
-
|
1207
|
-
would commit the transaction.
|
845
|
+
*Darwin Wu*
|
1208
846
|
|
1209
|
-
|
1210
|
-
|
847
|
+
* Configuration item `config.filter_parameters` could also filter out
|
848
|
+
sensitive values of database columns when calling `#inspect`.
|
849
|
+
We also added `ActiveRecord::Base::filter_attributes`/`=` in order to
|
850
|
+
specify sensitive attributes to specific model.
|
1211
851
|
|
1212
|
-
|
852
|
+
```
|
853
|
+
Rails.application.config.filter_parameters += [:credit_card_number, /phone/]
|
854
|
+
Account.last.inspect # => #<Account id: 123, name: "DHH", credit_card_number: [FILTERED], telephone_number: [FILTERED] ...>
|
855
|
+
SecureAccount.filter_attributes += [:name]
|
856
|
+
SecureAccount.last.inspect # => #<SecureAccount id: 42, name: [FILTERED], credit_card_number: [FILTERED] ...>
|
857
|
+
```
|
1213
858
|
|
1214
|
-
|
1215
|
-
t.index :zip
|
1216
|
-
end
|
1217
|
-
# => CREATE TEMPORARY TABLE temp (INDEX (zip)) AS SELECT id, name, zip FROM a_really_complicated_query
|
859
|
+
*Zhang Kang*, *Yoshiyuki Kinjo*
|
1218
860
|
|
1219
|
-
|
861
|
+
* Deprecate `column_name_length`, `table_name_length`, `columns_per_table`,
|
862
|
+
`indexes_per_table`, `columns_per_multicolumn_index`, `sql_query_length`,
|
863
|
+
and `joins_per_query` methods in `DatabaseLimits`.
|
1220
864
|
|
1221
|
-
*
|
1222
|
-
`ActiveRecord::Base.pluralize_table_names` is `false`.
|
865
|
+
*Ryuta Kamizono*
|
1223
866
|
|
1224
|
-
|
867
|
+
* `ActiveRecord::Base.configurations` now returns an object.
|
1225
868
|
|
1226
|
-
|
869
|
+
`ActiveRecord::Base.configurations` used to return a hash, but this
|
870
|
+
is an inflexible data model. In order to improve multiple-database
|
871
|
+
handling in Rails, we've changed this to return an object. Some methods
|
872
|
+
are provided to make the object behave hash-like in order to ease the
|
873
|
+
transition process. Since most applications don't manipulate the hash
|
874
|
+
we've decided to add backwards-compatible functionality that will throw
|
875
|
+
a deprecation warning if used, however calling `ActiveRecord::Base.configurations`
|
876
|
+
will use the new version internally and externally.
|
1227
877
|
|
1228
|
-
|
878
|
+
For example, the following `database.yml`:
|
1229
879
|
|
1230
|
-
|
880
|
+
```
|
881
|
+
development:
|
882
|
+
adapter: sqlite3
|
883
|
+
database: db/development.sqlite3
|
884
|
+
```
|
1231
885
|
|
1232
|
-
|
1233
|
-
Photo.last.touch(:signed_at, :sealed_at)
|
886
|
+
Used to become a hash:
|
1234
887
|
|
1235
|
-
|
888
|
+
```
|
889
|
+
{ "development" => { "adapter" => "sqlite3", "database" => "db/development.sqlite3" } }
|
890
|
+
```
|
1236
891
|
|
1237
|
-
|
1238
|
-
migration table exists.
|
892
|
+
Is now converted into the following object:
|
1239
893
|
|
1240
|
-
|
894
|
+
```
|
895
|
+
#<ActiveRecord::DatabaseConfigurations:0x00007fd1acbdf800 @configurations=[
|
896
|
+
#<ActiveRecord::DatabaseConfigurations::HashConfig:0x00007fd1acbded10 @env_name="development",
|
897
|
+
@spec_name="primary", @config={"adapter"=>"sqlite3", "database"=>"db/development.sqlite3"}>
|
898
|
+
]
|
899
|
+
```
|
1241
900
|
|
1242
|
-
|
901
|
+
Iterating over the database configurations has also changed. Instead of
|
902
|
+
calling hash methods on the `configurations` hash directly, a new method `configs_for` has
|
903
|
+
been provided that allows you to select the correct configuration. `env_name` and
|
904
|
+
`spec_name` arguments are optional. For example, these return an array of
|
905
|
+
database config objects for the requested environment and a single database config object
|
906
|
+
will be returned for the requested environment and specification name respectively.
|
1243
907
|
|
1244
|
-
|
1245
|
-
|
1246
|
-
|
1247
|
-
|
1248
|
-
the same time.
|
908
|
+
```
|
909
|
+
ActiveRecord::Base.configurations.configs_for(env_name: "development")
|
910
|
+
ActiveRecord::Base.configurations.configs_for(env_name: "development", spec_name: "primary")
|
911
|
+
```
|
1249
912
|
|
1250
|
-
*
|
913
|
+
*Eileen M. Uchitelle*, *Aaron Patterson*
|
1251
914
|
|
1252
|
-
*
|
1253
|
-
pointing to pg_class, and thus only sequence objects, are considered.
|
915
|
+
* Add database configuration to disable advisory locks.
|
1254
916
|
|
1255
|
-
|
917
|
+
```
|
918
|
+
production:
|
919
|
+
adapter: postgresql
|
920
|
+
advisory_locks: false
|
921
|
+
```
|
1256
922
|
|
1257
|
-
*
|
923
|
+
*Guo Xiang*
|
1258
924
|
|
1259
|
-
|
925
|
+
* SQLite3 adapter `alter_table` method restores foreign keys.
|
1260
926
|
|
1261
|
-
*
|
927
|
+
*Yasuo Honda*
|
1262
928
|
|
1263
|
-
*
|
929
|
+
* Allow `:to_table` option to `invert_remove_foreign_key`.
|
1264
930
|
|
1265
931
|
Example:
|
1266
932
|
|
1267
|
-
|
1268
|
-
email: $LABEL@email.com
|
933
|
+
remove_foreign_key :accounts, to_table: :owners
|
1269
934
|
|
1270
|
-
|
935
|
+
*Nikolay Epifanov*, *Rich Chen*
|
1271
936
|
|
1272
|
-
|
937
|
+
* Add environment & load_config dependency to `bin/rake db:seed` to enable
|
938
|
+
seed load in environments without Rails and custom DB configuration
|
1273
939
|
|
1274
|
-
*
|
940
|
+
*Tobias Bielohlawek*
|
1275
941
|
|
1276
|
-
|
942
|
+
* Fix default value for mysql time types with specified precision.
|
1277
943
|
|
1278
|
-
*
|
1279
|
-
|
1280
|
-
* Passing an Active Record object to `find` or `exists?` is now deprecated.
|
1281
|
-
Call `.id` on the object first.
|
1282
|
-
|
1283
|
-
*Aaron Patterson*
|
944
|
+
*Nikolay Kondratyev*
|
1284
945
|
|
1285
|
-
*
|
1286
|
-
has a case insensitive collation.
|
946
|
+
* Fix `touch` option to behave consistently with `Persistence#touch` method.
|
1287
947
|
|
1288
948
|
*Ryuta Kamizono*
|
1289
949
|
|
1290
|
-
*
|
1291
|
-
|
1292
|
-
*arthurnn*, *Tatsuhiko Miyagawa*
|
950
|
+
* Migrations raise when duplicate column definition.
|
1293
951
|
|
1294
|
-
|
1295
|
-
`where` values without needing to wrap in UPPER/LOWER sql functions.
|
952
|
+
Fixes #33024.
|
1296
953
|
|
1297
|
-
*
|
954
|
+
*Federico Martinez*
|
1298
955
|
|
1299
|
-
*
|
1300
|
-
Previously after save related callbacks, such as `#after_commit`, were triggered when the has_one
|
1301
|
-
object did not get saved to the db.
|
956
|
+
* Bump minimum SQLite version to 3.8
|
1302
957
|
|
1303
|
-
*
|
958
|
+
*Yasuo Honda*
|
1304
959
|
|
1305
|
-
*
|
960
|
+
* Fix parent record should not get saved with duplicate children records.
|
1306
961
|
|
1307
|
-
|
962
|
+
Fixes #32940.
|
1308
963
|
|
1309
|
-
|
964
|
+
*Santosh Wadghule*
|
1310
965
|
|
1311
|
-
|
966
|
+
* Fix logic on disabling commit callbacks so they are not called unexpectedly when errors occur.
|
1312
967
|
|
1313
|
-
*
|
1314
|
-
warnings on enum columns.
|
968
|
+
*Brian Durand*
|
1315
969
|
|
1316
|
-
|
970
|
+
* Ensure `Associations::CollectionAssociation#size` and `Associations::CollectionAssociation#empty?`
|
971
|
+
use loaded association ids if present.
|
1317
972
|
|
1318
|
-
*
|
1319
|
-
joins are involved.
|
973
|
+
*Graham Turner*
|
1320
974
|
|
1321
|
-
|
975
|
+
* Add support to preload associations of polymorphic associations when not all the records have the requested associations.
|
1322
976
|
|
1323
|
-
*
|
977
|
+
*Dana Sherson*
|
1324
978
|
|
1325
|
-
*
|
1326
|
-
any enum attribute is always evaluated as 0 during uniqueness validation.
|
979
|
+
* Add `touch_all` method to `ActiveRecord::Relation`.
|
1327
980
|
|
1328
|
-
|
981
|
+
Example:
|
1329
982
|
|
1330
|
-
|
983
|
+
Person.where(name: "David").touch_all(time: Time.new(2020, 5, 16, 0, 0, 0))
|
1331
984
|
|
1332
|
-
*
|
1333
|
-
`has_and_belongs_to_many` associations *and* on `has_many :through`
|
1334
|
-
associations. Before this change, `before_add` callbacks would be fired
|
1335
|
-
before the record was saved on `has_and_belongs_to_many` associations, but
|
1336
|
-
*not* on `has_many :through` associations.
|
985
|
+
*fatkodima*, *duggiefresh*
|
1337
986
|
|
1338
|
-
|
987
|
+
* Add `ActiveRecord::Base.base_class?` predicate.
|
1339
988
|
|
1340
|
-
*
|
1341
|
-
private method defined on its ancestors.
|
989
|
+
*Bogdan Gusiev*
|
1342
990
|
|
1343
|
-
|
991
|
+
* Add custom prefix/suffix options to `ActiveRecord::Store.store_accessor`.
|
1344
992
|
|
1345
|
-
*
|
993
|
+
*Tan Huynh*, *Yukio Mizuta*
|
1346
994
|
|
1347
|
-
*
|
995
|
+
* Rails 6 requires Ruby 2.5.0 or newer.
|
1348
996
|
|
1349
|
-
|
997
|
+
*Jeremy Daer*, *Kasper Timm Hansen*
|
1350
998
|
|
1351
|
-
|
1352
|
-
book.save!
|
1353
|
-
book.title # => "12345"
|
999
|
+
* Deprecate `update_attributes`/`!` in favor of `update`/`!`.
|
1354
1000
|
|
1355
|
-
*
|
1001
|
+
*Eddie Lebow*
|
1356
1002
|
|
1357
|
-
*
|
1358
|
-
|
1359
|
-
possible because the Ruby range does not support excluded beginnings.
|
1003
|
+
* Add `ActiveRecord::Base.create_or_find_by`/`!` to deal with the SELECT/INSERT race condition in
|
1004
|
+
`ActiveRecord::Base.find_or_create_by`/`!` by leaning on unique constraints in the database.
|
1360
1005
|
|
1361
|
-
|
1362
|
-
deprecated. For subtypes where we don't know how to increment (e.g. `#succ`
|
1363
|
-
is not defined) it will raise an `ArgumentException` for ranges with excluding
|
1364
|
-
beginnings.
|
1006
|
+
*DHH*
|
1365
1007
|
|
1366
|
-
|
1008
|
+
* Add `Relation#pick` as short-hand for single-value plucks.
|
1367
1009
|
|
1368
|
-
*
|
1010
|
+
*DHH*
|
1369
1011
|
|
1370
|
-
*Yves Senn*
|
1371
1012
|
|
1372
|
-
Please check [
|
1013
|
+
Please check [5-2-stable](https://github.com/rails/rails/blob/5-2-stable/activerecord/CHANGELOG.md) for previous changes.
|