activerecord 4.2.11.1 → 6.0.3.5
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 +721 -1522
- data/MIT-LICENSE +4 -2
- data/README.rdoc +14 -13
- data/examples/performance.rb +33 -32
- data/examples/simple.rb +5 -4
- data/lib/active_record/advisory_lock_base.rb +18 -0
- data/lib/active_record/aggregations.rb +266 -251
- data/lib/active_record/association_relation.rb +20 -13
- data/lib/active_record/associations/alias_tracker.rb +29 -36
- data/lib/active_record/associations/association.rb +128 -57
- data/lib/active_record/associations/association_scope.rb +103 -132
- data/lib/active_record/associations/belongs_to_association.rb +65 -60
- 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 -33
- data/lib/active_record/associations/builder/has_and_belongs_to_many.rb +50 -66
- 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 +136 -288
- data/lib/active_record/associations/collection_proxy.rb +241 -147
- data/lib/active_record/associations/foreign_association.rb +10 -1
- data/lib/active_record/associations/has_many_association.rb +34 -98
- data/lib/active_record/associations/has_many_through_association.rb +60 -87
- data/lib/active_record/associations/has_one_association.rb +61 -49
- data/lib/active_record/associations/has_one_through_association.rb +20 -11
- data/lib/active_record/associations/join_dependency/join_association.rb +38 -86
- 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 +149 -166
- data/lib/active_record/associations/preloader/association.rb +90 -123
- data/lib/active_record/associations/preloader/through_association.rb +85 -65
- data/lib/active_record/associations/preloader.rb +90 -93
- data/lib/active_record/associations/singular_association.rb +18 -39
- data/lib/active_record/associations/through_association.rb +38 -18
- data/lib/active_record/associations.rb +1737 -1597
- data/lib/active_record/attribute_assignment.rb +57 -185
- data/lib/active_record/attribute_decorators.rb +39 -17
- data/lib/active_record/attribute_methods/before_type_cast.rb +13 -9
- data/lib/active_record/attribute_methods/dirty.rb +174 -144
- data/lib/active_record/attribute_methods/primary_key.rb +90 -84
- data/lib/active_record/attribute_methods/query.rb +6 -5
- data/lib/active_record/attribute_methods/read.rb +20 -77
- data/lib/active_record/attribute_methods/serialization.rb +40 -21
- data/lib/active_record/attribute_methods/time_zone_conversion.rb +57 -37
- data/lib/active_record/attribute_methods/write.rb +32 -55
- data/lib/active_record/attribute_methods.rb +120 -135
- data/lib/active_record/attributes.rb +213 -82
- data/lib/active_record/autosave_association.rb +97 -41
- data/lib/active_record/base.rb +57 -45
- data/lib/active_record/callbacks.rb +101 -76
- data/lib/active_record/coders/json.rb +3 -1
- data/lib/active_record/coders/yaml_column.rb +23 -12
- data/lib/active_record/connection_adapters/abstract/connection_pool.rb +804 -297
- data/lib/active_record/connection_adapters/abstract/database_limits.rb +26 -8
- data/lib/active_record/connection_adapters/abstract/database_statements.rb +240 -115
- data/lib/active_record/connection_adapters/abstract/query_cache.rb +83 -24
- data/lib/active_record/connection_adapters/abstract/quoting.rb +170 -53
- data/lib/active_record/connection_adapters/abstract/savepoints.rb +5 -3
- data/lib/active_record/connection_adapters/abstract/schema_creation.rb +74 -47
- data/lib/active_record/connection_adapters/abstract/schema_definitions.rb +371 -242
- data/lib/active_record/connection_adapters/abstract/schema_dumper.rb +79 -36
- data/lib/active_record/connection_adapters/abstract/schema_statements.rb +694 -256
- data/lib/active_record/connection_adapters/abstract/transaction.rb +190 -83
- data/lib/active_record/connection_adapters/abstract_adapter.rb +473 -202
- data/lib/active_record/connection_adapters/abstract_mysql_adapter.rb +507 -639
- data/lib/active_record/connection_adapters/column.rb +56 -43
- data/lib/active_record/connection_adapters/connection_specification.rb +174 -153
- 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 +196 -0
- data/lib/active_record/connection_adapters/mysql/explain_pretty_printer.rb +71 -0
- data/lib/active_record/connection_adapters/mysql/quoting.rb +81 -0
- data/lib/active_record/connection_adapters/mysql/schema_creation.rb +71 -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 +58 -181
- data/lib/active_record/connection_adapters/postgresql/column.rb +21 -11
- data/lib/active_record/connection_adapters/postgresql/database_statements.rb +70 -114
- data/lib/active_record/connection_adapters/postgresql/explain_pretty_printer.rb +44 -0
- data/lib/active_record/connection_adapters/postgresql/oid/array.rb +49 -58
- 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 +4 -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 -22
- data/lib/active_record/connection_adapters/postgresql/oid/decimal.rb +3 -1
- data/lib/active_record/connection_adapters/postgresql/oid/enum.rb +5 -4
- data/lib/active_record/connection_adapters/postgresql/oid/hstore.rb +31 -20
- 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 +44 -0
- data/lib/active_record/connection_adapters/postgresql/oid/money.rb +7 -9
- data/lib/active_record/connection_adapters/postgresql/oid/{infinity.rb → oid.rb} +5 -3
- data/lib/active_record/connection_adapters/postgresql/oid/point.rb +32 -11
- data/lib/active_record/connection_adapters/postgresql/oid/range.rb +51 -34
- data/lib/active_record/connection_adapters/postgresql/oid/specialized_string.rb +4 -5
- data/lib/active_record/connection_adapters/postgresql/oid/type_map_initializer.rb +58 -54
- data/lib/active_record/connection_adapters/postgresql/oid/uuid.rb +9 -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 +49 -0
- data/lib/active_record/connection_adapters/postgresql/schema_statements.rb +462 -296
- data/lib/active_record/connection_adapters/postgresql/type_metadata.rb +36 -0
- data/lib/active_record/connection_adapters/postgresql/utils.rb +11 -8
- data/lib/active_record/connection_adapters/postgresql_adapter.rb +558 -356
- 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 +119 -0
- data/lib/active_record/connection_adapters/sqlite3/explain_pretty_printer.rb +21 -0
- data/lib/active_record/connection_adapters/sqlite3/quoting.rb +102 -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 +299 -349
- data/lib/active_record/connection_adapters/statement_pool.rb +33 -13
- data/lib/active_record/connection_handling.rb +167 -41
- data/lib/active_record/core.rb +252 -230
- data/lib/active_record/counter_cache.rb +70 -49
- 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 +78 -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 -106
- data/lib/active_record/enum.rb +163 -86
- data/lib/active_record/errors.rb +188 -53
- data/lib/active_record/explain.rb +22 -11
- data/lib/active_record/explain_registry.rb +4 -2
- data/lib/active_record/explain_subscriber.rb +10 -5
- 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 +152 -0
- data/lib/active_record/fixture_set/table_rows.rb +46 -0
- data/lib/active_record/fixtures.rb +227 -501
- data/lib/active_record/gem_version.rb +6 -4
- data/lib/active_record/inheritance.rb +158 -115
- 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 +21 -3
- data/lib/active_record/locale/en.yml +3 -2
- data/lib/active_record/locking/optimistic.rb +86 -96
- 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 +87 -0
- data/lib/active_record/middleware/database_selector.rb +74 -0
- data/lib/active_record/migration/command_recorder.rb +166 -91
- data/lib/active_record/migration/compatibility.rb +244 -0
- data/lib/active_record/migration/join_table.rb +8 -7
- data/lib/active_record/migration.rb +623 -305
- data/lib/active_record/model_schema.rb +313 -112
- data/lib/active_record/nested_attributes.rb +263 -223
- data/lib/active_record/no_touching.rb +15 -2
- data/lib/active_record/null_relation.rb +24 -38
- data/lib/active_record/persistence.rb +557 -126
- data/lib/active_record/query_cache.rb +19 -23
- data/lib/active_record/querying.rb +44 -30
- data/lib/active_record/railtie.rb +143 -44
- 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 +331 -185
- data/lib/active_record/readonly_attributes.rb +5 -4
- data/lib/active_record/reflection.rb +430 -281
- data/lib/active_record/relation/batches/batch_enumerator.rb +69 -0
- data/lib/active_record/relation/batches.rb +206 -55
- data/lib/active_record/relation/calculations.rb +268 -254
- data/lib/active_record/relation/delegation.rb +75 -84
- data/lib/active_record/relation/finder_methods.rb +285 -241
- data/lib/active_record/relation/from_clause.rb +30 -0
- data/lib/active_record/relation/merger.rb +78 -88
- data/lib/active_record/relation/predicate_builder/array_handler.rb +27 -26
- 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 +110 -119
- data/lib/active_record/relation/query_attribute.rb +50 -0
- data/lib/active_record/relation/query_methods.rb +603 -397
- data/lib/active_record/relation/record_fetch_warning.rb +51 -0
- data/lib/active_record/relation/spawn_methods.rb +11 -14
- data/lib/active_record/relation/where_clause.rb +189 -0
- data/lib/active_record/relation/where_clause_factory.rb +33 -0
- data/lib/active_record/relation.rb +530 -341
- data/lib/active_record/result.rb +79 -43
- 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 -17
- data/lib/active_record/scoping/default.rb +98 -83
- data/lib/active_record/scoping/named.rb +86 -33
- data/lib/active_record/scoping.rb +45 -27
- 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 +90 -0
- data/lib/active_record/tasks/database_tasks.rb +307 -100
- data/lib/active_record/tasks/mysql_database_tasks.rb +55 -100
- data/lib/active_record/tasks/postgresql_database_tasks.rb +80 -41
- data/lib/active_record/tasks/sqlite_database_tasks.rb +37 -16
- data/lib/active_record/test_databases.rb +23 -0
- data/lib/active_record/test_fixtures.rb +225 -0
- data/lib/active_record/timestamp.rb +86 -41
- data/lib/active_record/touch_later.rb +65 -0
- data/lib/active_record/transactions.rb +223 -157
- data/lib/active_record/translation.rb +3 -1
- data/lib/active_record/type/adapter_specific_registry.rb +126 -0
- data/lib/active_record/type/date.rb +4 -45
- data/lib/active_record/type/date_time.rb +4 -49
- data/lib/active_record/type/decimal_without_scale.rb +6 -2
- data/lib/active_record/type/hash_lookup_type_map.rb +5 -4
- 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 +23 -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 +16 -19
- data/lib/active_record/type/unsigned_integer.rb +9 -8
- data/lib/active_record/type.rb +77 -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 +12 -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 +42 -55
- data/lib/active_record/validations.rb +38 -35
- data/lib/active_record/version.rb +3 -1
- data/lib/active_record.rb +42 -22
- 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 +256 -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 +203 -0
- data/lib/arel/visitors/dot.rb +296 -0
- data/lib/arel/visitors/ibm_db.rb +34 -0
- data/lib/arel/visitors/informix.rb +62 -0
- data/lib/arel/visitors/mssql.rb +156 -0
- data/lib/arel/visitors/mysql.rb +83 -0
- data/lib/arel/visitors/oracle.rb +158 -0
- data/lib/arel/visitors/oracle12.rb +65 -0
- data/lib/arel/visitors/postgresql.rb +109 -0
- data/lib/arel/visitors/sqlite.rb +38 -0
- data/lib/arel/visitors/to_sql.rb +888 -0
- data/lib/arel/visitors/visitor.rb +45 -0
- data/lib/arel/visitors/where_sql.rb +22 -0
- data/lib/arel/visitors.rb +20 -0
- data/lib/arel/window_predications.rb +9 -0
- data/lib/arel.rb +62 -0
- data/lib/rails/generators/active_record/application_record/application_record_generator.rb +26 -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 -2
- data/lib/rails/generators/active_record/migration.rb +30 -1
- data/lib/rails/generators/active_record/model/model_generator.rb +18 -22
- data/lib/rails/generators/active_record/model/templates/model.rb.tt +22 -0
- data/lib/rails/generators/active_record/model/templates/{module.rb → module.rb.tt} +0 -0
- data/lib/rails/generators/active_record.rb +7 -5
- metadata +168 -59
- 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 -163
- data/lib/active_record/attribute_set/builder.rb +0 -106
- data/lib/active_record/attribute_set.rb +0 -81
- data/lib/active_record/connection_adapters/mysql_adapter.rb +0 -498
- 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/integer.rb +0 -11
- 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 -31
- data/lib/active_record/type/decimal.rb +0 -64
- 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 -59
- 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 -40
- data/lib/active_record/type/time_value.rb +0 -38
- data/lib/active_record/type/value.rb +0 -110
- data/lib/rails/generators/active_record/migration/templates/create_table_migration.rb +0 -19
- data/lib/rails/generators/active_record/model/templates/model.rb +0 -10
data/CHANGELOG.md
CHANGED
@@ -1,2033 +1,1232 @@
|
|
1
|
-
## Rails
|
1
|
+
## Rails 6.0.3.5 (February 10, 2021) ##
|
2
2
|
|
3
|
-
*
|
4
|
-
|
5
|
-
|
6
|
-
## Rails 4.2.11 (November 27, 2018) ##
|
7
|
-
|
8
|
-
* No changes.
|
9
|
-
|
10
|
-
|
11
|
-
## Rails 4.2.10 (September 27, 2017) ##
|
12
|
-
|
13
|
-
* `Relation#joins` is no longer affected by the target model's
|
14
|
-
`current_scope`, with the exception of `unscoped`.
|
15
|
-
|
16
|
-
Fixes #29338.
|
17
|
-
|
18
|
-
*Sean Griffin*
|
19
|
-
|
20
|
-
## Rails 4.2.9 (June 26, 2017) ##
|
21
|
-
|
22
|
-
* Fix regression caused by `collection_singular_ids=` ignoring different primary key on relationship.
|
23
|
-
|
24
|
-
*Nick Pezza*
|
25
|
-
|
26
|
-
* Fix `rake db:schema:load` with subdirectories.
|
27
|
-
|
28
|
-
*Ryuta Kamizono*
|
29
|
-
|
30
|
-
* Fix `rake db:migrate:status` with subdirectories.
|
31
|
-
|
32
|
-
*Ryuta Kamizono*
|
33
|
-
|
34
|
-
* Fix regression of #1969 with SELECT aliases in HAVING clause.
|
35
|
-
|
36
|
-
*Eugene Kenny*
|
37
|
-
|
38
|
-
* Fix `wait_timeout` to configurable for mysql2 adapter.
|
39
|
-
|
40
|
-
Fixes #26556.
|
41
|
-
|
42
|
-
*Ryuta Kamizono*
|
43
|
-
|
44
|
-
* Make `table_name=` reset current statement cache,
|
45
|
-
so queries are not run against the previous table name.
|
46
|
-
|
47
|
-
*namusyaka*
|
48
|
-
|
49
|
-
|
50
|
-
## Rails 4.2.8 (February 21, 2017) ##
|
51
|
-
|
52
|
-
* Using a mysql2 connection after it fails to reconnect will now have an error message
|
53
|
-
saying the connection is closed rather than an undefined method error message.
|
54
|
-
|
55
|
-
*Dylan Thacker-Smith*
|
56
|
-
|
57
|
-
* Bust Model.attribute_names cache when resetting column information
|
58
|
-
|
59
|
-
*James Coleman*
|
60
|
-
|
61
|
-
* Fix query caching when type information is reset
|
62
|
-
|
63
|
-
Backports ancillary fix in 5.0.
|
64
|
-
|
65
|
-
*James Coleman*
|
66
|
-
|
67
|
-
* Allow `joins` to be unscoped.
|
68
|
-
|
69
|
-
Fixes #13775.
|
70
|
-
|
71
|
-
*Takashi Kokubun*
|
72
|
-
|
73
|
-
* Hashes can once again be passed to setters of `composed_of`, if all of the
|
74
|
-
mapping methods are methods implemented on `Hash`.
|
75
|
-
|
76
|
-
Fixes #25978.
|
77
|
-
|
78
|
-
*Sean Griffin*
|
79
|
-
|
80
|
-
|
81
|
-
## Rails 4.2.7 (July 12, 2016) ##
|
82
|
-
|
83
|
-
* Inspecting an object with an associated array of over 10 elements no longer
|
84
|
-
truncates the array, preventing `inspect` from looping infinitely in some
|
85
|
-
cases.
|
86
|
-
|
87
|
-
*Kevin McPhillips*
|
88
|
-
|
89
|
-
* Ensure hashes can be assigned to attributes created using `composed_of`.
|
90
|
-
Fixes #25210.
|
91
|
-
|
92
|
-
*Sean Griffin*
|
93
|
-
|
94
|
-
* Queries such as `Computer.joins(:monitor).group(:status).count` will now be
|
95
|
-
interpreted as `Computer.joins(:monitor).group('computers.status').count`
|
96
|
-
so that when `Computer` and `Monitor` have both `status` columns we don't
|
97
|
-
have conflicts in projection.
|
98
|
-
|
99
|
-
*Rafael Sales*
|
100
|
-
|
101
|
-
* ActiveRecord::Relation#count: raise an ArgumentError when finder options
|
102
|
-
are specified or an ActiveRecord::StatementInvalid when an invalid type
|
103
|
-
is provided for a column name (e.g. a Hash).
|
104
|
-
|
105
|
-
Fixes #20434
|
106
|
-
|
107
|
-
*Konstantinos Rousis*
|
108
|
-
|
109
|
-
* Correctly pass MySQL options when using structure_dump or structure_load
|
110
|
-
|
111
|
-
Specifically, it fixes an issue when using SSL authentication.
|
112
|
-
|
113
|
-
*Alex Coomans*
|
114
|
-
|
115
|
-
|
116
|
-
## Rails 4.2.6 (March 07, 2016) ##
|
117
|
-
|
118
|
-
* Fix a bug where using `t.foreign_key` twice with the same `to_table` within
|
119
|
-
the same table definition would only create one foreign key.
|
3
|
+
* Fix possible DoS vector in PostgreSQL money type
|
120
4
|
|
121
|
-
|
5
|
+
Carefully crafted input can cause a DoS via the regular expressions used
|
6
|
+
for validating the money format in the PostgreSQL adapter. This patch
|
7
|
+
fixes the regexp.
|
122
8
|
|
123
|
-
|
124
|
-
clone no longer show as changed attributes in the original object.
|
9
|
+
Thanks to @dee-see from Hackerone for this patch!
|
125
10
|
|
126
|
-
|
11
|
+
[CVE-2021-22880]
|
127
12
|
|
128
|
-
*
|
129
|
-
|
130
|
-
Closes #22584.
|
131
|
-
|
132
|
-
*Yves Senn*
|
133
|
-
|
134
|
-
* Fix `rake db:structure:dump` on Postgres when multiple schemas are used.
|
135
|
-
|
136
|
-
Fixes #22346.
|
137
|
-
|
138
|
-
*Nick Muerdter*, *ckoenig*
|
139
|
-
|
140
|
-
* Introduce `connection.data_sources` and `connection.data_source_exists?`.
|
141
|
-
These methods determine what relations can be used to back Active Record
|
142
|
-
models (usually tables and views).
|
143
|
-
|
144
|
-
*Yves Senn*, *Matthew Draper*
|
13
|
+
*Aaron Patterson*
|
145
14
|
|
146
15
|
|
147
|
-
## Rails
|
16
|
+
## Rails 6.0.3.4 (October 07, 2020) ##
|
148
17
|
|
149
18
|
* No changes.
|
150
19
|
|
151
20
|
|
152
|
-
## Rails
|
21
|
+
## Rails 6.0.3.3 (September 09, 2020) ##
|
153
22
|
|
154
23
|
* No changes.
|
155
24
|
|
156
25
|
|
157
|
-
## Rails
|
26
|
+
## Rails 6.0.3.2 (June 17, 2020) ##
|
158
27
|
|
159
|
-
* No
|
160
|
-
|
161
|
-
*Paul Sadauskas*
|
28
|
+
* No changes.
|
162
29
|
|
163
|
-
* Set `scope.reordering_value` to `true` if :reordering values are specified.
|
164
30
|
|
165
|
-
|
31
|
+
## Rails 6.0.3.1 (May 18, 2020) ##
|
166
32
|
|
167
|
-
|
33
|
+
* No changes.
|
168
34
|
|
169
|
-
* Avoid disabling errors on the PostgreSQL connection when enabling the
|
170
|
-
standard_conforming_strings setting. Errors were previously disabled because
|
171
|
-
the setting wasn't writable in Postgres 8.1 and didn't exist in earlier
|
172
|
-
versions. Now Rails only supports Postgres 8.2+ we're fine to assume the
|
173
|
-
setting exists. Disabling errors caused problems when using a connection
|
174
|
-
pooling tool like PgBouncer because it's not guaranteed to have the same
|
175
|
-
connection between calls to `execute` and it could leave the connection
|
176
|
-
with errors disabled.
|
177
35
|
|
178
|
-
|
36
|
+
## Rails 6.0.3 (May 06, 2020) ##
|
179
37
|
|
180
|
-
|
38
|
+
* Recommend applications don't use the `database` kwarg in `connected_to`
|
181
39
|
|
182
|
-
|
183
|
-
only instantiates one HABTM object because the join table hasn't a primary key.
|
40
|
+
The database kwarg in `connected_to` was meant to be used for one-off scripts but is often used in requests. This is really dangerous because it re-establishes a connection every time. It's deprecated in 6.1 and will be removed in 6.2 without replacement. This change soft deprecates it in 6.0 by removing documentation.
|
184
41
|
|
185
|
-
|
42
|
+
*Eileen M. Uchitelle*
|
186
43
|
|
187
|
-
|
44
|
+
* Fix support for PostgreSQL 11+ partitioned indexes.
|
188
45
|
|
189
|
-
|
46
|
+
*Sebastián Palma*
|
190
47
|
|
191
|
-
|
192
|
-
Project.includes(:salaried_developers).first.salaried_developers.size # => 1
|
48
|
+
* Add support for beginless ranges, introduced in Ruby 2.7.
|
193
49
|
|
194
|
-
|
50
|
+
*Josh Goodall*
|
195
51
|
|
196
|
-
|
197
|
-
Project.includes(:salaried_developers).first.salaried_developers.size # => 3
|
52
|
+
* Fix insert_all with enum values
|
198
53
|
|
199
|
-
|
54
|
+
Fixes #38716.
|
200
55
|
|
201
|
-
*
|
56
|
+
*Joel Blum*
|
202
57
|
|
203
|
-
|
58
|
+
* Regexp-escape table name for MS SQL
|
204
59
|
|
205
|
-
|
60
|
+
Add `Regexp.escape` to one method in ActiveRecord, so that table names with regular expression characters in them work as expected. Since MS SQL Server uses "[" and "]" to quote table and column names, and those characters are regular expression characters, methods like `pluck` and `select` fail in certain cases when used with the MS SQL Server adapter.
|
206
61
|
|
207
|
-
*
|
208
|
-
`ActiveRecord::Tasks::DatabaseTasks.migrations_paths` instead of
|
209
|
-
`Migrator.migrations_paths`.
|
62
|
+
*Larry Reid*
|
210
63
|
|
211
|
-
|
64
|
+
* Store advisory locks on their own named connection.
|
212
65
|
|
213
|
-
|
66
|
+
Previously advisory locks were taken out against a connection when a migration started. This works fine in single database applications but doesn't work well when migrations need to open new connections which results in the lock getting dropped.
|
214
67
|
|
215
|
-
|
68
|
+
In order to fix this we are storing the advisory lock on a new connection with the connection specification name `AdisoryLockBase`. The caveat is that we need to maintain at least 2 connections to a database while migrations are running in order to do this.
|
216
69
|
|
217
|
-
*
|
70
|
+
*Eileen M. Uchitelle*, *John Crepezzi*
|
218
71
|
|
219
|
-
*
|
220
|
-
drying up Kernel.system() calls within this namespace and to avoid
|
221
|
-
shell expansion by using a paramter list instead of string as arguments
|
222
|
-
for Kernel.system(). Thanks to Nate Berkopec for supply patch to get
|
223
|
-
test units passing.
|
72
|
+
* Ensure `:reading` connections always raise if a write is attempted.
|
224
73
|
|
225
|
-
|
74
|
+
Now Rails will raise an `ActiveRecord::ReadOnlyError` if any connection on the reading handler attempts to make a write. If your reading role needs to write you should name the role something other than `:reading`.
|
226
75
|
|
227
|
-
*
|
76
|
+
*Eileen M. Uchitelle*
|
228
77
|
|
229
|
-
|
78
|
+
* Enforce fresh ETag header after a collection's contents change by adding
|
79
|
+
ActiveRecord::Relation#cache_key_with_version. This method will be used by
|
80
|
+
ActionController::ConditionalGet to ensure that when collection cache versioning
|
81
|
+
is enabled, requests using ConditionalGet don't return the same ETag header
|
82
|
+
after a collection is modified. Fixes #38078.
|
230
83
|
|
231
|
-
*
|
84
|
+
*Aaron Lipman*
|
232
85
|
|
233
|
-
*
|
234
|
-
to Rails 4.2
|
86
|
+
* A database URL can now contain a querystring value that contains an equal sign. This is needed to support passing PostgresSQL `options`.
|
235
87
|
|
236
|
-
|
88
|
+
*Joshua Flanagan*
|
237
89
|
|
238
|
-
*
|
90
|
+
* Retain explicit selections on the base model after applying `includes` and `joins`.
|
239
91
|
|
240
|
-
|
92
|
+
Resolves #34889.
|
241
93
|
|
242
|
-
*
|
94
|
+
*Patrick Rebsch*
|
243
95
|
|
244
|
-
Fixes #21488
|
245
96
|
|
246
|
-
|
97
|
+
## Rails 6.0.2.2 (March 19, 2020) ##
|
247
98
|
|
248
|
-
*
|
99
|
+
* No changes.
|
249
100
|
|
250
|
-
*Ben Murphy*, *Matthew Draper*
|
251
101
|
|
252
|
-
|
253
|
-
record without primary key.
|
102
|
+
## Rails 6.0.2.1 (December 18, 2019) ##
|
254
103
|
|
255
|
-
|
104
|
+
* No changes.
|
256
105
|
|
257
|
-
*Yves Senn*
|
258
106
|
|
107
|
+
## Rails 6.0.2 (December 13, 2019) ##
|
259
108
|
|
260
|
-
|
109
|
+
* Share the same connection pool for primary and replica databases in the
|
110
|
+
transactional tests for the same database.
|
261
111
|
|
262
|
-
*
|
112
|
+
*Edouard Chin*
|
263
113
|
|
264
|
-
|
265
|
-
|
114
|
+
* Fix the preloader when one record is fetched using `after_initialize`
|
115
|
+
but not the entire collection.
|
266
116
|
|
267
|
-
|
117
|
+
*Bradley Price*
|
268
118
|
|
269
|
-
|
119
|
+
* Fix collection callbacks not terminating when `:abort` is thrown.
|
270
120
|
|
271
|
-
*
|
272
|
-
the limit: 8 was not coming through. This caused it to become Int[] data type
|
273
|
-
after doing a rebuild off of schema.rb.
|
121
|
+
*Edouard Chin*, *Ryuta Kamizono*
|
274
122
|
|
275
|
-
|
123
|
+
* Correctly deprecate `where.not` working as NOR for relations.
|
276
124
|
|
277
|
-
|
125
|
+
12a9664 deprecated where.not working as NOR, however
|
126
|
+
doing a relation query like `where.not(relation: { ... })`
|
127
|
+
wouldn't be properly deprecated and `where.not` would work as
|
128
|
+
NAND instead.
|
278
129
|
|
279
|
-
|
280
|
-
Before we had `new_record?` returning `true` for a persisted record:
|
130
|
+
*Edouard Chin*
|
281
131
|
|
282
|
-
|
283
|
-
|
284
|
-
author.save # => false
|
285
|
-
author.new_record? # => true
|
132
|
+
* Fix `db:migrate` task with multiple databases to restore the connection
|
133
|
+
to the previous database.
|
286
134
|
|
287
|
-
|
135
|
+
The migrate task iterates and establish a connection over each db
|
136
|
+
resulting in the last one to be used by subsequent rake tasks.
|
137
|
+
We should reestablish a connection to the connection that was
|
138
|
+
established before the migrate tasks was run
|
288
139
|
|
289
|
-
*
|
140
|
+
*Edouard Chin*
|
290
141
|
|
291
|
-
*
|
292
|
-
when validating associations.
|
142
|
+
* Fix multi-threaded issue for `AcceptanceValidator`.
|
293
143
|
|
294
|
-
|
144
|
+
*Ryuta Kamizono*
|
295
145
|
|
296
|
-
*Sean Griffin*
|
297
146
|
|
298
|
-
|
299
|
-
times.
|
147
|
+
## Rails 6.0.1 (November 5, 2019) ##
|
300
148
|
|
301
|
-
|
302
|
-
Fixes #20727.
|
149
|
+
* Common Table Expressions are allowed on read-only connections.
|
303
150
|
|
304
|
-
|
151
|
+
*Chris Morris*
|
305
152
|
|
306
|
-
*
|
307
|
-
other than `db:migrate`. (eg. `db:rollback`, `db:migrate:dup`, ...)
|
153
|
+
* New record instantiation respects `unscope`.
|
308
154
|
|
309
|
-
|
155
|
+
*Ryuta Kamizono*
|
310
156
|
|
311
|
-
|
157
|
+
* Fixed a case where `find_in_batches` could halt too early.
|
312
158
|
|
313
|
-
*
|
314
|
-
a wrong type to a namespaced association.
|
159
|
+
*Takayuki Nakata*
|
315
160
|
|
316
|
-
|
161
|
+
* Autosaved associations always perform validations when a custom validation
|
162
|
+
context is used.
|
317
163
|
|
318
|
-
|
164
|
+
*Tekin Suleyman*
|
319
165
|
|
320
|
-
*
|
321
|
-
|
166
|
+
* `sql.active_record` notifications now include the `:connection` in
|
167
|
+
their payloads.
|
322
168
|
|
323
|
-
|
169
|
+
*Eugene Kenny*
|
324
170
|
|
325
|
-
|
171
|
+
* A rollback encountered in an `after_commit` callback does not reset
|
172
|
+
previously-committed record state.
|
326
173
|
|
174
|
+
*Ryuta Kamizono*
|
327
175
|
|
328
|
-
|
176
|
+
* Fixed that join order was lost when eager-loading.
|
329
177
|
|
330
|
-
*
|
178
|
+
*Ryuta Kamizono*
|
331
179
|
|
332
|
-
|
180
|
+
* `DESCRIBE` queries are allowed on read-only connections.
|
333
181
|
|
334
|
-
*
|
182
|
+
*Dylan Thacker-Smith*
|
335
183
|
|
336
|
-
|
184
|
+
* Fixed that records that had been `inspect`ed could not be marshaled.
|
337
185
|
|
338
|
-
*
|
339
|
-
`update_attributes` from a getter.
|
186
|
+
*Eugene Kenny*
|
340
187
|
|
341
|
-
|
188
|
+
* The connection pool reaper thread is respawned in forked processes. This
|
189
|
+
fixes that idle connections in forked processes wouldn't be reaped.
|
342
190
|
|
343
|
-
*
|
191
|
+
*John Hawthorn*
|
344
192
|
|
345
|
-
*
|
346
|
-
|
193
|
+
* The memoized result of `ActiveRecord::Relation#take` is properly cleared
|
194
|
+
when `ActiveRecord::Relation#reset` or `ActiveRecord::Relation#reload`
|
195
|
+
is called.
|
347
196
|
|
348
|
-
|
197
|
+
*Anmol Arora*
|
349
198
|
|
350
|
-
|
199
|
+
* Fixed the performance regression for `primary_keys` introduced MySQL 8.0.
|
351
200
|
|
352
|
-
*
|
201
|
+
*Hiroyuki Ishii*
|
353
202
|
|
354
|
-
|
203
|
+
* `insert`, `insert_all`, `upsert`, and `upsert_all` now clear the query cache.
|
355
204
|
|
356
|
-
*
|
357
|
-
underlying `has_many :through`.
|
205
|
+
*Eugene Kenny*
|
358
206
|
|
359
|
-
|
207
|
+
* Call `while_preventing_writes` directly from `connected_to`.
|
360
208
|
|
361
|
-
|
209
|
+
In some cases application authors want to use the database switching middleware and make explicit calls with `connected_to`. It's possible for an app to turn off writes and not turn them back on by the time we call `connected_to(role: :writing)`.
|
362
210
|
|
363
|
-
|
211
|
+
This change allows apps to fix this by assuming if a role is writing we want to allow writes, except in the case it's explicitly turned off.
|
364
212
|
|
365
|
-
*
|
366
|
-
environment. This ensures that initializers are run.
|
213
|
+
*Eileen M. Uchitelle*
|
367
214
|
|
368
|
-
|
215
|
+
* Improve detection of ActiveRecord::StatementTimeout with mysql2 adapter in the edge case when the query is terminated during filesort.
|
369
216
|
|
370
|
-
*
|
217
|
+
*Kir Shatrov*
|
371
218
|
|
372
|
-
* Fix missing index when using `timestamps` with the `index` option.
|
373
219
|
|
374
|
-
|
375
|
-
`column` definitions for `created_at` and `updated_at` rather than just
|
376
|
-
the first.
|
220
|
+
## Rails 6.0.0 (August 16, 2019) ##
|
377
221
|
|
378
|
-
|
222
|
+
* Preserve user supplied joins order as much as possible.
|
379
223
|
|
380
|
-
|
224
|
+
Fixes #36761, #34328, #24281, #12953.
|
381
225
|
|
382
|
-
|
226
|
+
*Ryuta Kamizono*
|
383
227
|
|
384
|
-
|
228
|
+
* Make the DATABASE_URL env variable only affect the primary connection. Add new env variables for multiple databases.
|
385
229
|
|
386
|
-
*
|
387
|
-
even if an validation should have prevented it from hitting the database.
|
230
|
+
*John Crepezzi*, *Eileen Uchitelle*
|
388
231
|
|
389
|
-
|
232
|
+
* Add a warning for enum elements with 'not_' prefix.
|
390
233
|
|
391
|
-
|
392
|
-
|
234
|
+
class Foo
|
235
|
+
enum status: [:sent, :not_sent]
|
236
|
+
end
|
393
237
|
|
394
|
-
|
238
|
+
*Edu Depetris*
|
395
239
|
|
396
|
-
|
240
|
+
* Make currency symbols optional for money column type in PostgreSQL
|
397
241
|
|
398
|
-
*
|
242
|
+
*Joel Schneider*
|
399
243
|
|
400
|
-
Fixes #19578.
|
401
244
|
|
402
|
-
|
245
|
+
## Rails 6.0.0.rc2 (July 22, 2019) ##
|
403
246
|
|
404
|
-
*
|
405
|
-
association (only when calling calculation methods).
|
247
|
+
* Add database_exists? method to connection adapters to check if a database exists.
|
406
248
|
|
407
|
-
|
249
|
+
*Guilherme Mansur*
|
408
250
|
|
409
|
-
|
251
|
+
* PostgreSQL: Fix GROUP BY with ORDER BY virtual count attribute.
|
410
252
|
|
411
|
-
|
253
|
+
Fixes #36022.
|
412
254
|
|
413
|
-
|
255
|
+
*Ryuta Kamizono*
|
414
256
|
|
415
|
-
|
257
|
+
* Make ActiveRecord `ConnectionPool.connections` method thread-safe.
|
416
258
|
|
417
|
-
|
418
|
-
its default value by an in-place modification.
|
259
|
+
Fixes #36465.
|
419
260
|
|
420
|
-
|
261
|
+
*Jeff Doering*
|
421
262
|
|
422
|
-
|
263
|
+
* Fix sqlite3 collation parsing when using decimal columns.
|
423
264
|
|
424
|
-
*
|
265
|
+
*Martin R. Schuster*
|
425
266
|
|
426
|
-
|
267
|
+
* Fix invalid schema when primary key column has a comment.
|
427
268
|
|
428
|
-
|
429
|
-
That was causing a memory grow problem when creating a lot of records inside a transaction.
|
269
|
+
Fixes #29966.
|
430
270
|
|
431
|
-
|
271
|
+
*Guilherme Goettems Schneider*
|
432
272
|
|
433
|
-
|
273
|
+
* Fix table comment also being applied to the primary key column.
|
434
274
|
|
435
|
-
*
|
436
|
-
association when using `where`.
|
275
|
+
*Guilherme Goettems Schneider*
|
437
276
|
|
438
|
-
|
277
|
+
* Fix merging left_joins to maintain its own `join_type` context.
|
439
278
|
|
440
|
-
|
279
|
+
Fixes #36103.
|
441
280
|
|
281
|
+
*Ryuta Kamizono*
|
442
282
|
|
443
|
-
## Rails 4.2.2 (June 16, 2015) ##
|
444
283
|
|
445
|
-
|
284
|
+
## Rails 6.0.0.rc1 (April 24, 2019) ##
|
446
285
|
|
286
|
+
* Add `touch` option to `has_one` association.
|
447
287
|
|
448
|
-
|
288
|
+
*Abhay Nikam*
|
449
289
|
|
450
|
-
*
|
290
|
+
* Deprecate `where.not` working as NOR and will be changed to NAND in Rails 6.1.
|
451
291
|
|
452
|
-
|
292
|
+
```ruby
|
293
|
+
all = [treasures(:diamond), treasures(:sapphire), cars(:honda), treasures(:sapphire)]
|
294
|
+
assert_equal all, PriceEstimate.all.map(&:estimate_of)
|
295
|
+
```
|
453
296
|
|
454
|
-
|
297
|
+
In Rails 6.0:
|
455
298
|
|
456
|
-
|
457
|
-
|
458
|
-
the column on MySQL.
|
299
|
+
```ruby
|
300
|
+
sapphire = treasures(:sapphire)
|
459
301
|
|
460
|
-
|
302
|
+
nor = all.reject { |e|
|
303
|
+
e.estimate_of_type == sapphire.class.polymorphic_name
|
304
|
+
}.reject { |e|
|
305
|
+
e.estimate_of_id == sapphire.id
|
306
|
+
}
|
307
|
+
assert_equal [cars(:honda)], nor
|
461
308
|
|
462
|
-
|
309
|
+
without_sapphire = PriceEstimate.where.not(
|
310
|
+
estimate_of_type: sapphire.class.polymorphic_name, estimate_of_id: sapphire.id
|
311
|
+
)
|
312
|
+
assert_equal nor, without_sapphire.map(&:estimate_of)
|
313
|
+
```
|
463
314
|
|
464
|
-
|
465
|
-
methods. The model and migration generators now use this option, rather than
|
466
|
-
the `add_foreign_key` form.
|
315
|
+
In Rails 6.1:
|
467
316
|
|
468
|
-
|
317
|
+
```ruby
|
318
|
+
sapphire = treasures(:sapphire)
|
469
319
|
|
470
|
-
|
320
|
+
nand = all - [sapphire]
|
321
|
+
assert_equal [treasures(:diamond), cars(:honda)], nand
|
471
322
|
|
472
|
-
|
473
|
-
|
323
|
+
without_sapphire = PriceEstimate.where.not(
|
324
|
+
estimate_of_type: sapphire.class.polymorphic_name, estimate_of_id: sapphire.id
|
325
|
+
)
|
326
|
+
assert_equal nand, without_sapphire.map(&:estimate_of)
|
327
|
+
```
|
474
328
|
|
475
329
|
*Ryuta Kamizono*
|
476
330
|
|
477
|
-
*
|
331
|
+
* Fix dirty tracking after rollback.
|
478
332
|
|
479
|
-
|
480
|
-
on the database default charset and collation rather than the encoding
|
481
|
-
of the connection.
|
333
|
+
Fixes #15018, #30167, #33868.
|
482
334
|
|
483
335
|
*Ryuta Kamizono*
|
484
336
|
|
485
|
-
*
|
486
|
-
|
487
|
-
|
488
|
-
|
489
|
-
*Sean Griffin*
|
490
|
-
|
491
|
-
* Fixed several edge cases which could result in a counter cache updating
|
492
|
-
twice or not updating at all for `has_many` and `has_many :through`.
|
493
|
-
|
494
|
-
Fixes #10865.
|
495
|
-
|
496
|
-
*Sean Griffin*
|
497
|
-
|
498
|
-
* Foreign keys added by migrations were given random, generated names. This
|
499
|
-
meant a different `structure.sql` would be generated every time a developer
|
500
|
-
ran migrations on their machine.
|
501
|
-
|
502
|
-
The generated part of foreign key names is now a hash of the table name and
|
503
|
-
column name, which is consistent every time you run the migration.
|
504
|
-
|
505
|
-
*Chris Sinjakli*
|
506
|
-
|
507
|
-
* Fixed ActiveRecord::Relation#group method when argument is SQL reserved key word:
|
508
|
-
|
509
|
-
SplitTest.group(:key).count
|
510
|
-
Property.group(:value).count
|
511
|
-
|
512
|
-
*Bogdan Gusiev*
|
513
|
-
|
514
|
-
* Don't define autosave association callbacks twice from
|
515
|
-
`accepts_nested_attributes_for`.
|
516
|
-
|
517
|
-
Fixes #18704.
|
518
|
-
|
519
|
-
*Sean Griffin*
|
520
|
-
|
521
|
-
* Integer types will no longer raise a `RangeError` when assigning an
|
522
|
-
attribute, but will instead raise when going to the database.
|
523
|
-
|
524
|
-
Fixes several vague issues which were never reported directly. See the
|
525
|
-
commit message from the commit which added this line for some examples.
|
526
|
-
|
527
|
-
*Sean Griffin*
|
528
|
-
|
529
|
-
* Values which would error while being sent to the database (such as an
|
530
|
-
ASCII-8BIT string with invalid UTF-8 bytes on Sqlite3), no longer error on
|
531
|
-
assignment. They will still error when sent to the database, but you are
|
532
|
-
given the ability to re-assign it to a valid value.
|
533
|
-
|
534
|
-
Fixes #18580.
|
535
|
-
|
536
|
-
*Sean Griffin*
|
537
|
-
|
538
|
-
* Don't remove join dependencies in `Relation#exists?`
|
539
|
-
|
540
|
-
Fixes #18632.
|
541
|
-
|
542
|
-
*Sean Griffin*
|
543
|
-
|
544
|
-
* Invalid values assigned to a JSON column are assumed to be `nil`.
|
337
|
+
* Add `ActiveRecord::Relation#cache_version` to support recyclable cache keys via
|
338
|
+
the versioned entries in `ActiveSupport::Cache`. This also means that
|
339
|
+
`ActiveRecord::Relation#cache_key` will now return a stable key that does not
|
340
|
+
include the max timestamp or count any more.
|
545
341
|
|
546
|
-
|
342
|
+
NOTE: This feature is turned off by default, and `cache_key` will still return
|
343
|
+
cache keys with timestamps until you set `ActiveRecord::Base.collection_cache_versioning = true`.
|
344
|
+
That's the setting for all new apps on Rails 6.0+
|
547
345
|
|
548
|
-
*
|
549
|
-
|
550
|
-
* No longer issue deprecation warning when including a scope with extensions.
|
551
|
-
Previously every scope with extension methods was transformed into an
|
552
|
-
instance dependent scope. Including such a scope would wrongfully issue a
|
553
|
-
deprecation warning. This is no longer the case.
|
554
|
-
|
555
|
-
Fixes #18467.
|
556
|
-
|
557
|
-
*Yves Senn*
|
558
|
-
|
559
|
-
* Correctly use the type provided by `serialize` when updating records using
|
560
|
-
optimistic locking.
|
561
|
-
|
562
|
-
Fixes #18385.
|
563
|
-
|
564
|
-
*Sean Griffin*
|
565
|
-
|
566
|
-
* `attribute_will_change!` will no longer cause non-persistable attributes to
|
567
|
-
be sent to the database.
|
568
|
-
|
569
|
-
Fixes #18407.
|
346
|
+
*Lachlan Sylvester*
|
570
347
|
|
571
|
-
|
348
|
+
* Fix dirty tracking for `touch` to track saved changes.
|
572
349
|
|
573
|
-
|
350
|
+
Fixes #33429.
|
574
351
|
|
575
|
-
|
352
|
+
*Ryuta Kamzono*
|
576
353
|
|
577
|
-
|
578
|
-
|
354
|
+
* `change_column_comment` and `change_table_comment` are invertible only if
|
355
|
+
`to` and `from` options are specified.
|
579
356
|
|
580
|
-
|
357
|
+
*Yoshiyuki Kinjo*
|
581
358
|
|
582
|
-
|
359
|
+
* Don't call commit/rollback callbacks when a record isn't saved.
|
583
360
|
|
584
|
-
|
361
|
+
Fixes #29747.
|
585
362
|
|
586
363
|
*Ryuta Kamizono*
|
587
364
|
|
588
|
-
*
|
589
|
-
|
590
|
-
*Florian Weingarten*
|
591
|
-
|
592
|
-
* Fixed setting of foreign_key for through associations while building of new record.
|
593
|
-
|
594
|
-
Fixes #12698.
|
365
|
+
* Fix circular `autosave: true` causes invalid records to be saved.
|
595
366
|
|
596
|
-
|
367
|
+
Prior to the fix, when there was a circular series of `autosave: true`
|
368
|
+
associations, the callback for a `has_many` association was run while
|
369
|
+
another instance of the same callback on the same association hadn't
|
370
|
+
finished running. When control returned to the first instance of the
|
371
|
+
callback, the instance variable had changed, and subsequent associated
|
372
|
+
records weren't saved correctly. Specifically, the ID field for the
|
373
|
+
`belongs_to` corresponding to the `has_many` was `nil`.
|
597
374
|
|
598
|
-
|
375
|
+
Fixes #28080.
|
599
376
|
|
600
|
-
*
|
377
|
+
*Larry Reid*
|
601
378
|
|
602
|
-
*
|
379
|
+
* Raise `ArgumentError` for invalid `:limit` and `:precision` like as other options.
|
603
380
|
|
604
|
-
|
605
|
-
|
606
|
-
*korbin*
|
607
|
-
|
608
|
-
* Fix error message when trying to create an associated record and the foreign
|
609
|
-
key is missing.
|
610
|
-
|
611
|
-
Before this fix the following exception was being raised:
|
612
|
-
|
613
|
-
NoMethodError: undefined method `val' for #<Arel::Nodes::BindParam:0x007fc64d19c218>
|
614
|
-
|
615
|
-
Now the message is:
|
616
|
-
|
617
|
-
ActiveRecord::UnknownAttributeError: unknown attribute 'foreign_key' for Model.
|
618
|
-
|
619
|
-
*Rafael Mendonça França*
|
620
|
-
|
621
|
-
* Fix change detection problem for PostgreSQL bytea type and
|
622
|
-
`ArgumentError: string contains null byte` exception with pg-0.18.
|
623
|
-
|
624
|
-
Fixes #17680.
|
625
|
-
|
626
|
-
*Lars Kanis*
|
627
|
-
|
628
|
-
* When a table has a composite primary key, the `primary_key` method for
|
629
|
-
SQLite3 and PostgreSQL adapters was only returning the first field of the key.
|
630
|
-
Ensures that it will return nil instead, as Active Record doesn't support
|
631
|
-
composite primary keys.
|
632
|
-
|
633
|
-
Fixes #18070.
|
634
|
-
|
635
|
-
*arthurnn*
|
636
|
-
|
637
|
-
* Ensure `first!` and friends work on loaded associations.
|
381
|
+
Before:
|
638
382
|
|
639
|
-
|
383
|
+
```ruby
|
384
|
+
add_column :items, :attr1, :binary, size: 10 # => ArgumentError
|
385
|
+
add_column :items, :attr2, :decimal, scale: 10 # => ArgumentError
|
386
|
+
add_column :items, :attr3, :integer, limit: 10 # => ActiveRecordError
|
387
|
+
add_column :items, :attr4, :datetime, precision: 10 # => ActiveRecordError
|
388
|
+
```
|
640
389
|
|
641
|
-
|
390
|
+
After:
|
642
391
|
|
643
|
-
|
392
|
+
```ruby
|
393
|
+
add_column :items, :attr1, :binary, size: 10 # => ArgumentError
|
394
|
+
add_column :items, :attr2, :decimal, scale: 10 # => ArgumentError
|
395
|
+
add_column :items, :attr3, :integer, limit: 10 # => ArgumentError
|
396
|
+
add_column :items, :attr4, :datetime, precision: 10 # => ArgumentError
|
397
|
+
```
|
644
398
|
|
645
399
|
*Ryuta Kamizono*
|
646
400
|
|
647
|
-
*
|
648
|
-
|
649
|
-
|
650
|
-
*Grey Baker*
|
651
|
-
|
652
|
-
* Fixes bug with 'ActiveRecord::Type::Numeric' that causes negative values to
|
653
|
-
be marked as having changed when set to the same negative value.
|
654
|
-
|
655
|
-
Fixes #18161.
|
656
|
-
|
657
|
-
*Daniel Fox*
|
658
|
-
|
659
|
-
|
660
|
-
## Rails 4.2.0 (December 20, 2014) ##
|
401
|
+
* Association loading isn't to be affected by scoping consistently
|
402
|
+
whether preloaded / eager loaded or not, with the exception of `unscoped`.
|
661
403
|
|
662
|
-
|
663
|
-
will recreate tables even if they have dependent objects (like foreign keys).
|
664
|
-
`db/schema.rb` now uses `force: :cascade`. This makes it possible to
|
665
|
-
reload the schema when foreign keys are in place.
|
666
|
-
|
667
|
-
*Matthew Draper*, *Yves Senn*
|
404
|
+
Before:
|
668
405
|
|
669
|
-
|
670
|
-
|
671
|
-
|
406
|
+
```ruby
|
407
|
+
Post.where("1=0").scoping do
|
408
|
+
Comment.find(1).post # => nil
|
409
|
+
Comment.preload(:post).find(1).post # => #<Post id: 1, ...>
|
410
|
+
Comment.eager_load(:post).find(1).post # => #<Post id: 1, ...>
|
411
|
+
end
|
412
|
+
```
|
672
413
|
|
673
|
-
|
414
|
+
After:
|
674
415
|
|
675
|
-
|
416
|
+
```ruby
|
417
|
+
Post.where("1=0").scoping do
|
418
|
+
Comment.find(1).post # => #<Post id: 1, ...>
|
419
|
+
Comment.preload(:post).find(1).post # => #<Post id: 1, ...>
|
420
|
+
Comment.eager_load(:post).find(1).post # => #<Post id: 1, ...>
|
421
|
+
end
|
422
|
+
```
|
676
423
|
|
677
|
-
|
424
|
+
Fixes #34638, #35398.
|
678
425
|
|
679
426
|
*Ryuta Kamizono*
|
680
427
|
|
681
|
-
* Add `
|
682
|
-
|
683
|
-
This option enables to define the column name of associated object's type for polymorphic associations.
|
684
|
-
|
685
|
-
*Ulisses Almeida, Kassio Borges*
|
686
|
-
|
687
|
-
* `add_timestamps` and `remove_timestamps` now properly reversible with
|
688
|
-
options.
|
689
|
-
|
690
|
-
*Noam Gagliardi-Rabinovich*
|
691
|
-
|
692
|
-
* Bring back `db:test:prepare` to synchronize the test database schema.
|
693
|
-
|
694
|
-
Manual synchronization using `bin/rake db:test:prepare` is required
|
695
|
-
when a migration is rolled-back, edited and reapplied.
|
696
|
-
|
697
|
-
`ActiveRecord::Base.maintain_test_schema` now uses `db:test:prepare`
|
698
|
-
to synchronize the schema. Plugins can use this task as a hook to
|
699
|
-
provide custom behavior after the schema has been loaded.
|
700
|
-
|
701
|
-
NOTE: `test:prepare` runs before the schema is synchronized.
|
702
|
-
|
703
|
-
Fixes #17171, #15787.
|
704
|
-
|
705
|
-
*Yves Senn*
|
706
|
-
|
707
|
-
* Change `reflections` public api to return the keys as String objects.
|
708
|
-
|
709
|
-
Fixes #16928.
|
710
|
-
|
711
|
-
*arthurnn*
|
712
|
-
|
713
|
-
* Renaming a table in pg also renames the primary key index.
|
714
|
-
|
715
|
-
Fixes #12856
|
716
|
-
|
717
|
-
*Sean Griffin*
|
718
|
-
|
719
|
-
* Make it possible to access fixtures excluded by a `default_scope`.
|
720
|
-
|
721
|
-
*Yves Senn*
|
722
|
-
|
723
|
-
* Fix preloading of associations with a scope containing joins along with
|
724
|
-
conditions on the joined association.
|
725
|
-
|
726
|
-
*Siddharth Sharma*
|
428
|
+
* Add `rails db:prepare` to migrate or setup a database.
|
727
429
|
|
728
|
-
|
430
|
+
Runs `db:migrate` if the database exists or `db:setup` if it doesn't.
|
729
431
|
|
730
|
-
*
|
432
|
+
*Roberto Miranda*
|
731
433
|
|
732
|
-
*
|
733
|
-
the owner has been saved so that the proxy is not cached without the
|
734
|
-
owner's id.
|
434
|
+
* Add `after_save_commit` callback as shortcut for `after_commit :hook, on: [ :create, :update ]`.
|
735
435
|
|
736
|
-
*
|
436
|
+
*DHH*
|
737
437
|
|
738
|
-
* `
|
438
|
+
* Assign all attributes before calling `build` to ensure the child record is visible in
|
439
|
+
`before_add` and `after_add` callbacks for `has_many :through` associations.
|
739
440
|
|
740
|
-
|
441
|
+
Fixes #33249.
|
741
442
|
|
742
|
-
*
|
443
|
+
*Ryan H. Kerr*
|
743
444
|
|
744
|
-
|
445
|
+
* Add `ActiveRecord::Relation#extract_associated` for extracting associated records from a relation.
|
745
446
|
|
746
|
-
|
447
|
+
```
|
448
|
+
account.memberships.extract_associated(:user)
|
449
|
+
# => Returns collection of User records
|
450
|
+
```
|
747
451
|
|
748
|
-
*
|
452
|
+
*DHH*
|
749
453
|
|
750
|
-
|
454
|
+
* Add `ActiveRecord::Relation#annotate` for adding SQL comments to its queries.
|
751
455
|
|
752
|
-
|
753
|
-
`Relation` for performing queries and updates is the prefered API.
|
456
|
+
For example:
|
754
457
|
|
755
|
-
|
756
|
-
|
757
|
-
|
758
|
-
|
759
|
-
|
760
|
-
*Melanie Gilman & Sean Griffin*
|
761
|
-
|
762
|
-
* MySQL enum type lookups, with values matching another type, no longer result
|
763
|
-
in an endless loop.
|
764
|
-
|
765
|
-
Fixes #17402.
|
766
|
-
|
767
|
-
*Yves Senn*
|
768
|
-
|
769
|
-
* Raise `ArgumentError` when the body of a scope is not callable.
|
770
|
-
|
771
|
-
*Mauro George*
|
772
|
-
|
773
|
-
* Use type column first in multi-column indexes created with `add-reference`.
|
774
|
-
|
775
|
-
*Derek Prior*
|
776
|
-
|
777
|
-
* Fix `Relation.rewhere` to work with Range values.
|
778
|
-
|
779
|
-
*Dan Olson*
|
780
|
-
|
781
|
-
* `AR::UnknownAttributeError` now includes the class name of a record.
|
782
|
-
|
783
|
-
User.new(name: "Yuki Nishijima", project_attributes: {name: "kaminari"})
|
784
|
-
# => ActiveRecord::UnknownAttributeError: unknown attribute 'name' for User.
|
785
|
-
|
786
|
-
*Yuki Nishijima*
|
787
|
-
|
788
|
-
* Fix a regression causing `after_create` callbacks to run before associated
|
789
|
-
records are autosaved.
|
790
|
-
|
791
|
-
Fixes #17209.
|
792
|
-
|
793
|
-
*Agis Anastasopoulos*
|
794
|
-
|
795
|
-
* Honor overridden `rack.test` in Rack environment for the connection
|
796
|
-
management middleware.
|
797
|
-
|
798
|
-
*Simon Eskildsen*
|
799
|
-
|
800
|
-
* Add a truncate method to the connection.
|
801
|
-
|
802
|
-
*Aaron Patterson*
|
803
|
-
|
804
|
-
* Don't autosave unchanged has_one through records.
|
805
|
-
|
806
|
-
*Alan Kennedy*, *Steve Parrington*
|
807
|
-
|
808
|
-
* Do not dump foreign keys for ignored tables.
|
809
|
-
|
810
|
-
*Yves Senn*
|
811
|
-
|
812
|
-
* PostgreSQL adapter correctly dumps foreign keys targeting tables
|
813
|
-
outside the schema search path.
|
814
|
-
|
815
|
-
Fixes #16907.
|
816
|
-
|
817
|
-
*Matthew Draper*, *Yves Senn*
|
818
|
-
|
819
|
-
* When a thread is killed, rollback the active transaction, instead of
|
820
|
-
committing it during the stack unwind. Previously, we could commit half-
|
821
|
-
completed work. This fix only works for Ruby 2.0+; on 1.9, we can't
|
822
|
-
distinguish a thread kill from an ordinary non-local (block) return, so must
|
823
|
-
default to committing.
|
824
|
-
|
825
|
-
*Chris Hanks*
|
458
|
+
```
|
459
|
+
Post.where(id: 123).annotate("this is a comment").to_sql
|
460
|
+
# SELECT "posts".* FROM "posts" WHERE "posts"."id" = 123 /* this is a comment */
|
461
|
+
```
|
826
462
|
|
827
|
-
|
828
|
-
`Comment.where(post_id: Post.none)` returned a non-empty result.
|
463
|
+
This can be useful in instrumentation or other analysis of issued queries.
|
829
464
|
|
830
|
-
|
465
|
+
*Matt Yoho*
|
831
466
|
|
832
|
-
|
467
|
+
* Support Optimizer Hints.
|
833
468
|
|
834
|
-
|
835
|
-
|
469
|
+
In most databases, a way to control the optimizer is by using optimizer hints,
|
470
|
+
which can be specified within individual statements.
|
836
471
|
|
837
|
-
|
472
|
+
Example (for MySQL):
|
838
473
|
|
839
|
-
|
840
|
-
|
841
|
-
*Jeremy Kemper*
|
842
|
-
|
843
|
-
* MySQL: correct LONGTEXT and LONGBLOB limits from 2GB to their true 4GB.
|
844
|
-
|
845
|
-
*Jeremy Kemper*
|
846
|
-
|
847
|
-
* SQLite3Adapter now checks for views in `table_exists?`. Fixes #14041.
|
848
|
-
|
849
|
-
*Girish Sonawane*
|
850
|
-
|
851
|
-
* Introduce `connection.supports_views?` to check whether the current adapter
|
852
|
-
has support for SQL views. Connection adapters should define this method.
|
853
|
-
|
854
|
-
*Yves Senn*
|
855
|
-
|
856
|
-
* Allow included modules to override association methods.
|
857
|
-
|
858
|
-
Fixes #16684.
|
859
|
-
|
860
|
-
*Yves Senn*
|
861
|
-
|
862
|
-
* Schema loading rake tasks (like `db:schema:load` and `db:setup`) maintain
|
863
|
-
the database connection to the current environment.
|
864
|
-
|
865
|
-
Fixes #16757.
|
866
|
-
|
867
|
-
*Joshua Cody*, *Yves Senn*
|
868
|
-
|
869
|
-
* MySQL: set the connection collation along with the charset.
|
870
|
-
|
871
|
-
Sets the connection collation to the database collation configured in
|
872
|
-
database.yml. Otherwise, `SET NAMES utf8mb4` will use the default
|
873
|
-
collation for that charset (utf8mb4_general_ci) when you may have chosen
|
874
|
-
a different collation, like utf8mb4_unicode_ci.
|
875
|
-
|
876
|
-
This only applies to literal string comparisons, not column values, so it
|
877
|
-
is unlikely to affect you.
|
878
|
-
|
879
|
-
*Jeremy Kemper*
|
880
|
-
|
881
|
-
* `default_sequence_name` from the PostgreSQL adapter returns a `String`.
|
882
|
-
|
883
|
-
*Yves Senn*
|
884
|
-
|
885
|
-
* Fix a regression where whitespaces were stripped from DISTINCT queries in
|
886
|
-
PostgreSQL.
|
887
|
-
|
888
|
-
*Agis Anastasopoulos*
|
889
|
-
|
890
|
-
Fixes #16623.
|
891
|
-
|
892
|
-
* Fix has_many :through relation merging failing when dynamic conditions are
|
893
|
-
passed as a lambda with an arity of one.
|
894
|
-
|
895
|
-
Fixes #16128.
|
896
|
-
|
897
|
-
*Agis Anastasopoulos*
|
898
|
-
|
899
|
-
* Fix `Relation#exists?` to work with polymorphic associations.
|
900
|
-
|
901
|
-
Fixes #15821.
|
902
|
-
|
903
|
-
*Kassio Borges*
|
904
|
-
|
905
|
-
* Currently, Active Record rescues any errors raised within
|
906
|
-
`after_rollback`/`after_create` callbacks and prints them to the logs.
|
907
|
-
Future versions of Rails will not rescue these errors anymore and
|
908
|
-
just bubble them up like the other callbacks.
|
909
|
-
|
910
|
-
This commit adds an opt-in flag to enable not rescuing the errors.
|
911
|
-
|
912
|
-
Example:
|
474
|
+
Topic.optimizer_hints("MAX_EXECUTION_TIME(50000)", "NO_INDEX_MERGE(topics)")
|
475
|
+
# SELECT /*+ MAX_EXECUTION_TIME(50000) NO_INDEX_MERGE(topics) */ `topics`.* FROM `topics`
|
913
476
|
|
914
|
-
|
915
|
-
config.active_record.raise_in_transactional_callbacks = true
|
477
|
+
Example (for PostgreSQL with pg_hint_plan):
|
916
478
|
|
917
|
-
|
479
|
+
Topic.optimizer_hints("SeqScan(topics)", "Parallel(topics 8)")
|
480
|
+
# SELECT /*+ SeqScan(topics) Parallel(topics 8) */ "topics".* FROM "topics"
|
918
481
|
|
919
|
-
|
482
|
+
See also:
|
920
483
|
|
921
|
-
*
|
922
|
-
|
923
|
-
|
484
|
+
* https://dev.mysql.com/doc/refman/8.0/en/optimizer-hints.html
|
485
|
+
* https://pghintplan.osdn.jp/pg_hint_plan.html
|
486
|
+
* https://docs.oracle.com/en/database/oracle/oracle-database/12.2/tgsql/influencing-the-optimizer.html
|
487
|
+
* https://docs.microsoft.com/en-us/sql/t-sql/queries/hints-transact-sql-query?view=sql-server-2017
|
488
|
+
* https://www.ibm.com/support/knowledgecenter/en/SSEPGG_11.1.0/com.ibm.db2.luw.admin.perf.doc/doc/c0070117.html
|
924
489
|
|
925
|
-
|
926
|
-
|
927
|
-
*Godfrey Chan*
|
928
|
-
|
929
|
-
* `*_was` and `changes` now work correctly for in-place attribute changes as
|
930
|
-
well.
|
931
|
-
|
932
|
-
*Sean Griffin*
|
933
|
-
|
934
|
-
* Fix regression on `after_commit` that did not fire with nested transactions.
|
935
|
-
|
936
|
-
Fixes #16425.
|
937
|
-
|
938
|
-
*arthurnn*
|
939
|
-
|
940
|
-
* Do not try to write timestamps when a table has no timestamps columns.
|
941
|
-
|
942
|
-
Fixes #8813.
|
943
|
-
|
944
|
-
*Sergey Potapov*
|
945
|
-
|
946
|
-
* `index_exists?` with `:name` option does verify specified columns.
|
947
|
-
|
948
|
-
Example:
|
949
|
-
|
950
|
-
add_index :articles, :title, name: "idx_title"
|
951
|
-
|
952
|
-
# Before:
|
953
|
-
index_exists? :articles, :title, name: "idx_title" # => `true`
|
954
|
-
index_exists? :articles, :body, name: "idx_title" # => `true`
|
955
|
-
|
956
|
-
# After:
|
957
|
-
index_exists? :articles, :title, name: "idx_title" # => `true`
|
958
|
-
index_exists? :articles, :body, name: "idx_title" # => `false`
|
959
|
-
|
960
|
-
*Yves Senn*, *Matthew Draper*
|
961
|
-
|
962
|
-
* `add_timestamps` and `t.timestamps` now require you to pass the `:null` option.
|
963
|
-
Not passing the option is deprecated but the default is still `null: true`.
|
964
|
-
With Rails 5 this will change to `null: false`.
|
965
|
-
|
966
|
-
*Sean Griffin*
|
967
|
-
|
968
|
-
* When calling `update_columns` on a record that is not persisted, the error
|
969
|
-
message now reflects whether that object is a new record or has been
|
970
|
-
destroyed.
|
971
|
-
|
972
|
-
*Lachlan Sylvester*
|
973
|
-
|
974
|
-
* Define `id_was` to get the previous value of the primary key.
|
975
|
-
|
976
|
-
Currently when we call `id_was` and we have a custom primary key name,
|
977
|
-
Active Record will return the current value of the primary key. This
|
978
|
-
makes it impossible to correctly do an update operation if you change the
|
979
|
-
id.
|
980
|
-
|
981
|
-
Fixes #16413.
|
982
|
-
|
983
|
-
*Rafael Mendonça França*
|
984
|
-
|
985
|
-
* Deprecate `DatabaseTasks.load_schema` to act on the current connection.
|
986
|
-
Use `.load_schema_current` instead. In the future `load_schema` will
|
987
|
-
require the `configuration` to act on as an argument.
|
988
|
-
|
989
|
-
*Yves Senn*
|
990
|
-
|
991
|
-
* Fix automatic maintaining test schema to properly handle sql structure
|
992
|
-
schema format.
|
993
|
-
|
994
|
-
Fixes #15394.
|
995
|
-
|
996
|
-
*Wojciech Wnętrzak*
|
997
|
-
|
998
|
-
* Fix type casting to Decimal from Float with large precision.
|
999
|
-
|
1000
|
-
*Tomohiro Hashidate*
|
1001
|
-
|
1002
|
-
* Deprecate `Reflection#source_macro`
|
1003
|
-
|
1004
|
-
`Reflection#source_macro` is no longer needed in Active Record
|
1005
|
-
source so it has been deprecated. Code that used `source_macro`
|
1006
|
-
was removed in #16353.
|
1007
|
-
|
1008
|
-
*Eileen M. Uchtitelle*, *Aaron Patterson*
|
1009
|
-
|
1010
|
-
* No verbose backtrace by `db:drop` when database does not exist.
|
1011
|
-
|
1012
|
-
Fixes #16295.
|
1013
|
-
|
1014
|
-
*Kenn Ejima*
|
1015
|
-
|
1016
|
-
* Add support for PostgreSQL JSONB.
|
490
|
+
*Ryuta Kamizono*
|
1017
491
|
|
1018
|
-
|
492
|
+
* Fix query attribute method on user-defined attribute to be aware of typecasted value.
|
1019
493
|
|
1020
|
-
|
1021
|
-
t.jsonb :meta_data
|
1022
|
-
end
|
494
|
+
For example, the following code no longer return false as casted non-empty string:
|
1023
495
|
|
1024
|
-
|
496
|
+
```
|
497
|
+
class Post < ActiveRecord::Base
|
498
|
+
attribute :user_defined_text, :text
|
499
|
+
end
|
1025
500
|
|
1026
|
-
|
501
|
+
Post.new(user_defined_text: "false").user_defined_text? # => true
|
502
|
+
```
|
1027
503
|
|
1028
|
-
*
|
504
|
+
*Yuji Kamijima*
|
1029
505
|
|
1030
|
-
*
|
1031
|
-
`DROP DEFAULT` instead of a `DEFAULT NULL` query.
|
506
|
+
* Quote empty ranges like other empty enumerables.
|
1032
507
|
|
1033
|
-
|
508
|
+
*Patrick Rebsch*
|
1034
509
|
|
1035
|
-
|
510
|
+
* Add `insert_all`/`insert_all!`/`upsert_all` methods to `ActiveRecord::Persistence`,
|
511
|
+
allowing bulk inserts akin to the bulk updates provided by `update_all` and
|
512
|
+
bulk deletes by `delete_all`.
|
1036
513
|
|
1037
|
-
|
1038
|
-
and `
|
514
|
+
Supports skipping or upserting duplicates through the `ON CONFLICT` syntax
|
515
|
+
for PostgreSQL (9.5+) and SQLite (3.24+) and `ON DUPLICATE KEY UPDATE` syntax
|
516
|
+
for MySQL.
|
1039
517
|
|
1040
|
-
|
518
|
+
*Bob Lail*
|
1041
519
|
|
1042
|
-
|
1043
|
-
|
1044
|
-
end
|
520
|
+
* Add `rails db:seed:replant` that truncates tables of each database
|
521
|
+
for current environment and loads the seeds.
|
1045
522
|
|
1046
|
-
*
|
523
|
+
*bogdanvlviv*, *DHH*
|
1047
524
|
|
1048
|
-
* `
|
1049
|
-
This matches the existing behavior of HABTM associations.
|
525
|
+
* Add `ActiveRecord::Base.connection.truncate` for SQLite3 adapter.
|
1050
526
|
|
1051
|
-
|
527
|
+
*bogdanvlviv*
|
1052
528
|
|
1053
|
-
|
529
|
+
* Deprecate mismatched collation comparison for uniqueness validator.
|
1054
530
|
|
1055
|
-
|
1056
|
-
|
531
|
+
Uniqueness validator will no longer enforce case sensitive comparison in Rails 6.1.
|
532
|
+
To continue case sensitive comparison on the case insensitive column,
|
533
|
+
pass `case_sensitive: true` option explicitly to the uniqueness validator.
|
1057
534
|
|
1058
|
-
*
|
535
|
+
*Ryuta Kamizono*
|
1059
536
|
|
1060
|
-
*
|
537
|
+
* Add `reselect` method. This is a short-hand for `unscope(:select).select(fields)`.
|
1061
538
|
|
1062
|
-
|
539
|
+
Fixes #27340.
|
1063
540
|
|
1064
|
-
*
|
541
|
+
*Willian Gustavo Veiga*
|
1065
542
|
|
1066
|
-
|
1067
|
-
the second attribute. It will now return a hash as per previous versions.
|
543
|
+
* Add negative scopes for all enum values.
|
1068
544
|
|
1069
545
|
Example:
|
1070
546
|
|
1071
547
|
class Post < ActiveRecord::Base
|
1072
|
-
|
548
|
+
enum status: %i[ drafted active trashed ]
|
1073
549
|
end
|
1074
550
|
|
1075
|
-
|
1076
|
-
|
1077
|
-
|
1078
|
-
end
|
1079
|
-
|
1080
|
-
post = Post.create!
|
1081
|
-
post.comment = Comment.new(category: "Animals", text: "This is a comment about squirrels.")
|
1082
|
-
post.save!
|
1083
|
-
|
1084
|
-
# 4.0
|
1085
|
-
post.comment # => {"category"=>"Animals", "text"=>"This is a comment about squirrels."}
|
1086
|
-
|
1087
|
-
# 4.1 before
|
1088
|
-
post.comment # => "#<Comment:0x007f80ab48ff98>"
|
1089
|
-
|
1090
|
-
# 4.1 after
|
1091
|
-
post.comment # => {"category"=>"Animals", "text"=>"This is a comment about squirrels."}
|
1092
|
-
|
1093
|
-
When using `JSON` as the coder in `serialize`, Active Record will use the
|
1094
|
-
new `ActiveRecord::Coders::JSON` coder which delegates its `dump/load` to
|
1095
|
-
`ActiveSupport::JSON.encode/decode`. This ensures special objects are dumped
|
1096
|
-
correctly using the `#as_json` hook.
|
1097
|
-
|
1098
|
-
To keep the previous behaviour, supply a custom coder instead
|
1099
|
-
([example](https://gist.github.com/jenncoop/8c4142bbe59da77daa63)).
|
1100
|
-
|
1101
|
-
Fixes #15594.
|
1102
|
-
|
1103
|
-
*Jenn Cooper*
|
1104
|
-
|
1105
|
-
* Do not use `RENAME INDEX` syntax for MariaDB 10.0.
|
1106
|
-
|
1107
|
-
Fixes #15931.
|
1108
|
-
|
1109
|
-
*Jeff Browning*
|
1110
|
-
|
1111
|
-
* Calling `#empty?` on a `has_many` association would use the value from the
|
1112
|
-
counter cache if one exists.
|
1113
|
-
|
1114
|
-
*David Verhasselt*
|
1115
|
-
|
1116
|
-
* Fix the schema dump generated for tables without constraints and with
|
1117
|
-
primary key with default value of custom PostgreSQL function result.
|
1118
|
-
|
1119
|
-
Fixes #16111.
|
551
|
+
Post.not_drafted # => where.not(status: :drafted)
|
552
|
+
Post.not_active # => where.not(status: :active)
|
553
|
+
Post.not_trashed # => where.not(status: :trashed)
|
1120
554
|
|
1121
|
-
*
|
555
|
+
*DHH*
|
1122
556
|
|
1123
|
-
* Fix
|
1124
|
-
produce an `IN` statements.
|
557
|
+
* Fix different `count` calculation when using `size` with manual `select` with DISTINCT.
|
1125
558
|
|
1126
|
-
|
1127
|
-
|
1128
|
-
UPDATE "categorizations" SET "category_id" = NULL WHERE
|
1129
|
-
"categorizations"."category_id" = 1 AND "categorizations"."id" IN (1, 2)
|
1130
|
-
|
1131
|
-
After:
|
1132
|
-
|
1133
|
-
UPDATE "categorizations" SET "category_id" = NULL WHERE
|
1134
|
-
"categorizations"."category_id" = 1
|
1135
|
-
|
1136
|
-
*Eileen M. Uchitelle, Aaron Patterson*
|
1137
|
-
|
1138
|
-
* Avoid type casting boolean and `ActiveSupport::Duration` values to numeric
|
1139
|
-
values for string columns. Otherwise, in some database, the string column
|
1140
|
-
values will be coerced to a numeric allowing false or 0.seconds match any
|
1141
|
-
string starting with a non-digit.
|
1142
|
-
|
1143
|
-
Example:
|
1144
|
-
|
1145
|
-
App.where(apikey: false) # => SELECT * FROM users WHERE apikey = '0'
|
1146
|
-
|
1147
|
-
*Dylan Thacker-Smith*
|
1148
|
-
|
1149
|
-
* Add a `:required` option to singular associations, providing a nicer
|
1150
|
-
API for presence validations on associations.
|
1151
|
-
|
1152
|
-
*Sean Griffin*
|
1153
|
-
|
1154
|
-
* Fix an error in `reset_counters` when associations have `select` scope.
|
1155
|
-
(Call to `count` generated invalid SQL.)
|
559
|
+
Fixes #35214.
|
1156
560
|
|
1157
|
-
*
|
561
|
+
*Juani Villarejo*
|
1158
562
|
|
1159
|
-
* After a successful `reload`, `new_record?` is always false.
|
1160
563
|
|
1161
|
-
|
564
|
+
## Rails 6.0.0.beta3 (March 11, 2019) ##
|
1162
565
|
|
1163
|
-
|
1164
|
-
|
1165
|
-
* PostgreSQL renaming table doesn't attempt to rename non existent sequences.
|
1166
|
-
|
1167
|
-
*Abdelkader Boudih*
|
1168
|
-
|
1169
|
-
* Move 'dependent: :destroy' handling for `belongs_to`
|
1170
|
-
from `before_destroy` to `after_destroy` callback chain
|
1171
|
-
|
1172
|
-
Fixes #12380.
|
1173
|
-
|
1174
|
-
*Ivan Antropov*
|
1175
|
-
|
1176
|
-
* Detect in-place modifications on String attributes.
|
566
|
+
* No changes.
|
1177
567
|
|
1178
|
-
Before this change, an attribute modified in-place had to be marked as
|
1179
|
-
changed in order for it to be persisted in the database. Now it is no longer
|
1180
|
-
required.
|
1181
568
|
|
1182
|
-
|
569
|
+
## Rails 6.0.0.beta2 (February 25, 2019) ##
|
1183
570
|
|
1184
|
-
|
1185
|
-
user.name << ' Griffin'
|
1186
|
-
user.name_will_change!
|
1187
|
-
user.save
|
1188
|
-
user.reload.name # => "Sean Griffin"
|
571
|
+
* Fix prepared statements caching to be enabled even when query caching is enabled.
|
1189
572
|
|
1190
|
-
|
573
|
+
*Ryuta Kamizono*
|
1191
574
|
|
1192
|
-
|
1193
|
-
user.name << ' Griffin'
|
1194
|
-
user.save
|
1195
|
-
user.reload.name # => "Sean Griffin"
|
575
|
+
* Ensure `update_all` series cares about optimistic locking.
|
1196
576
|
|
1197
|
-
*
|
577
|
+
*Ryuta Kamizono*
|
1198
578
|
|
1199
|
-
*
|
1200
|
-
is invalid.
|
579
|
+
* Don't allow `where` with non numeric string matches to 0 values.
|
1201
580
|
|
1202
|
-
*
|
581
|
+
*Ryuta Kamizono*
|
1203
582
|
|
1204
|
-
*
|
1205
|
-
a part of `schema.rb`. This is supported by Mysql2Adapter, MysqlAdapter
|
1206
|
-
and PostgreSQLAdapter.
|
583
|
+
* Introduce `ActiveRecord::Relation#destroy_by` and `ActiveRecord::Relation#delete_by`.
|
1207
584
|
|
1208
|
-
|
1209
|
-
|
585
|
+
`destroy_by` allows relation to find all the records matching the condition and perform
|
586
|
+
`destroy_all` on the matched records.
|
1210
587
|
|
1211
588
|
Example:
|
1212
589
|
|
1213
|
-
|
1214
|
-
|
1215
|
-
remove_foreign_key :articles, :authors
|
1216
|
-
|
1217
|
-
*Yves Senn*
|
1218
|
-
|
1219
|
-
* Fix subtle bugs regarding attribute assignment on models with no primary
|
1220
|
-
key. `'id'` will no longer be part of the attributes hash.
|
1221
|
-
|
1222
|
-
*Sean Griffin*
|
1223
|
-
|
1224
|
-
* Deprecate automatic counter caches on `has_many :through`. The behavior was
|
1225
|
-
broken and inconsistent.
|
1226
|
-
|
1227
|
-
*Sean Griffin*
|
590
|
+
Person.destroy_by(name: 'David')
|
591
|
+
Person.destroy_by(name: 'David', rating: 4)
|
1228
592
|
|
1229
|
-
|
593
|
+
david = Person.find_by(name: 'David')
|
594
|
+
david.posts.destroy_by(id: [1, 2, 3])
|
1230
595
|
|
1231
|
-
|
1232
|
-
|
1233
|
-
*Yves Senn*
|
1234
|
-
|
1235
|
-
* Assume numeric types have changed if they were assigned to a value that
|
1236
|
-
would fail numericality validation, regardless of the old value. Previously
|
1237
|
-
this would only occur if the old value was 0.
|
596
|
+
`delete_by` allows relation to find all the records matching the condition and perform
|
597
|
+
`delete_all` on the matched records.
|
1238
598
|
|
1239
599
|
Example:
|
1240
600
|
|
1241
|
-
|
1242
|
-
|
1243
|
-
model.number_changed? # => true
|
1244
|
-
|
1245
|
-
Fixes #14731.
|
1246
|
-
|
1247
|
-
*Sean Griffin*
|
1248
|
-
|
1249
|
-
* `reload` no longer merges with the existing attributes.
|
1250
|
-
The attribute hash is fully replaced. The record is put into the same state
|
1251
|
-
as it would be with `Model.find(model.id)`.
|
1252
|
-
|
1253
|
-
*Sean Griffin*
|
1254
|
-
|
1255
|
-
* The object returned from `select_all` must respond to `column_types`.
|
1256
|
-
If this is not the case a `NoMethodError` is raised.
|
1257
|
-
|
1258
|
-
*Sean Griffin*
|
1259
|
-
|
1260
|
-
* Detect in-place modifications of PG array types
|
601
|
+
Person.delete_by(name: 'David')
|
602
|
+
Person.delete_by(name: 'David', rating: 4)
|
1261
603
|
|
1262
|
-
|
1263
|
-
|
1264
|
-
* Add `bin/rake db:purge` task to empty the current database.
|
1265
|
-
|
1266
|
-
*Yves Senn*
|
1267
|
-
|
1268
|
-
* Deprecate `serialized_attributes` without replacement.
|
1269
|
-
|
1270
|
-
*Sean Griffin*
|
1271
|
-
|
1272
|
-
* Correctly extract IPv6 addresses from `DATABASE_URI`: the square brackets
|
1273
|
-
are part of the URI structure, not the actual host.
|
1274
|
-
|
1275
|
-
Fixes #15705.
|
604
|
+
david = Person.find_by(name: 'David')
|
605
|
+
david.posts.delete_by(id: [1, 2, 3])
|
1276
606
|
|
1277
|
-
*
|
607
|
+
*Abhay Nikam*
|
1278
608
|
|
1279
|
-
*
|
1280
|
-
through association are new.
|
609
|
+
* Don't allow `where` with invalid value matches to nil values.
|
1281
610
|
|
1282
|
-
|
1283
|
-
|
1284
|
-
* `ActiveRecord::Dirty` now detects in-place changes to mutable values.
|
1285
|
-
Serialized attributes on ActiveRecord models will no longer save when
|
1286
|
-
unchanged.
|
1287
|
-
|
1288
|
-
Fixes #8328.
|
1289
|
-
|
1290
|
-
*Sean Griffin*
|
1291
|
-
|
1292
|
-
* `Pluck` now works when selecting columns from different tables with the same
|
1293
|
-
name.
|
611
|
+
Fixes #33624.
|
1294
612
|
|
1295
|
-
|
1296
|
-
|
1297
|
-
*Sean Griffin*
|
1298
|
-
|
1299
|
-
* Remove `cache_attributes` and friends. All attributes are cached.
|
1300
|
-
|
1301
|
-
*Sean Griffin*
|
1302
|
-
|
1303
|
-
* Remove deprecated method `ActiveRecord::Base.quoted_locking_column`.
|
1304
|
-
|
1305
|
-
*Akshay Vishnoi*
|
1306
|
-
|
1307
|
-
* `ActiveRecord::FinderMethods.find` with block can handle proc parameter as
|
1308
|
-
`Enumerable#find` does.
|
1309
|
-
|
1310
|
-
Fixes #15382.
|
1311
|
-
|
1312
|
-
*James Yang*
|
1313
|
-
|
1314
|
-
* Make timezone aware attributes work with PostgreSQL array columns.
|
1315
|
-
|
1316
|
-
Fixes #13402.
|
1317
|
-
|
1318
|
-
*Kuldeep Aggarwal*, *Sean Griffin*
|
1319
|
-
|
1320
|
-
* `ActiveRecord::SchemaMigration` has no primary key regardless of the
|
1321
|
-
`primary_key_prefix_type` configuration.
|
1322
|
-
|
1323
|
-
Fixes #15051.
|
1324
|
-
|
1325
|
-
*JoseLuis Torres*, *Yves Senn*
|
1326
|
-
|
1327
|
-
* `rake db:migrate:status` works with legacy migration numbers like `00018_xyz.rb`.
|
1328
|
-
|
1329
|
-
Fixes #15538.
|
1330
|
-
|
1331
|
-
*Yves Senn*
|
1332
|
-
|
1333
|
-
* Baseclass becomes! subclass.
|
1334
|
-
|
1335
|
-
Before this change, a record which changed its STI type, could not be
|
1336
|
-
updated.
|
1337
|
-
|
1338
|
-
Fixes #14785.
|
1339
|
-
|
1340
|
-
*Matthew Draper*, *Earl St Sauver*, *Edo Balvers*
|
1341
|
-
|
1342
|
-
* Remove deprecated `ActiveRecord::Migrator.proper_table_name`. Use the
|
1343
|
-
`proper_table_name` instance method on `ActiveRecord::Migration` instead.
|
1344
|
-
|
1345
|
-
*Akshay Vishnoi*
|
1346
|
-
|
1347
|
-
* Fix regression on eager loading association based on SQL query rather than
|
1348
|
-
existing column.
|
1349
|
-
|
1350
|
-
Fixes #15480.
|
1351
|
-
|
1352
|
-
*Lauro Caetano*, *Carlos Antonio da Silva*
|
1353
|
-
|
1354
|
-
* Deprecate returning `nil` from `column_for_attribute` when no column exists.
|
1355
|
-
It will return a null object in Rails 5.0
|
1356
|
-
|
1357
|
-
*Sean Griffin*
|
1358
|
-
|
1359
|
-
* Implemented `ActiveRecord::Base#pretty_print` to work with PP.
|
1360
|
-
|
1361
|
-
*Ethan*
|
1362
|
-
|
1363
|
-
* Preserve type when dumping PostgreSQL point, bit, bit varying and money
|
1364
|
-
columns.
|
1365
|
-
|
1366
|
-
*Yves Senn*
|
1367
|
-
|
1368
|
-
* New records remain new after YAML serialization.
|
1369
|
-
|
1370
|
-
*Sean Griffin*
|
1371
|
-
|
1372
|
-
* PostgreSQL support default values for enum types. Fixes #7814.
|
1373
|
-
|
1374
|
-
*Yves Senn*
|
1375
|
-
|
1376
|
-
* PostgreSQL `default_sequence_name` respects schema. Fixes #7516.
|
1377
|
-
|
1378
|
-
*Yves Senn*
|
1379
|
-
|
1380
|
-
* Fix `columns_for_distinct` of PostgreSQL adapter to work correctly
|
1381
|
-
with orders without sort direction modifiers.
|
1382
|
-
|
1383
|
-
*Nikolay Kondratyev*
|
1384
|
-
|
1385
|
-
* PostgreSQL `reset_pk_sequence!` respects schemas. Fixes #14719.
|
1386
|
-
|
1387
|
-
*Yves Senn*
|
1388
|
-
|
1389
|
-
* Keep PostgreSQL `hstore` and `json` attributes as `Hash` in `@attributes`.
|
1390
|
-
Fixes duplication in combination with `store_accessor`.
|
1391
|
-
|
1392
|
-
Fixes #15369.
|
1393
|
-
|
1394
|
-
*Yves Senn*
|
1395
|
-
|
1396
|
-
* `rake railties:install:migrations` respects the order of railties.
|
1397
|
-
|
1398
|
-
*Arun Agrawal*
|
1399
|
-
|
1400
|
-
* Fix redefine a `has_and_belongs_to_many` inside inherited class
|
1401
|
-
Fixing regression case, where redefining the same `has_and_belongs_to_many`
|
1402
|
-
definition into a subclass would raise.
|
1403
|
-
|
1404
|
-
Fixes #14983.
|
1405
|
-
|
1406
|
-
*arthurnn*
|
1407
|
-
|
1408
|
-
* Fix `has_and_belongs_to_many` public reflection.
|
1409
|
-
When defining a `has_and_belongs_to_many`, internally we convert that to two has_many.
|
1410
|
-
But as `reflections` is a public API, people expect to see the right macro.
|
1411
|
-
|
1412
|
-
Fixes #14682.
|
1413
|
-
|
1414
|
-
*arthurnn*
|
1415
|
-
|
1416
|
-
* Fix serialization for records with an attribute named `format`.
|
1417
|
-
|
1418
|
-
Fixes #15188.
|
1419
|
-
|
1420
|
-
*Godfrey Chan*
|
1421
|
-
|
1422
|
-
* When a `group` is set, `sum`, `size`, `average`, `minimum` and `maximum`
|
1423
|
-
on a NullRelation should return a Hash.
|
1424
|
-
|
1425
|
-
*Kuldeep Aggarwal*
|
1426
|
-
|
1427
|
-
* Fix serialized fields returning serialized data after being updated with
|
1428
|
-
`update_column`.
|
613
|
+
*Ryuta Kamizono*
|
1429
614
|
|
1430
|
-
|
615
|
+
* SQLite3: Implement `add_foreign_key` and `remove_foreign_key`.
|
1431
616
|
|
1432
|
-
*
|
617
|
+
*Ryuta Kamizono*
|
1433
618
|
|
1434
|
-
|
619
|
+
* Deprecate using class level querying methods if the receiver scope
|
620
|
+
regarded as leaked. Use `klass.unscoped` to avoid the leaking scope.
|
1435
621
|
|
1436
|
-
*
|
622
|
+
*Ryuta Kamizono*
|
1437
623
|
|
1438
|
-
*
|
624
|
+
* Allow applications to automatically switch connections.
|
1439
625
|
|
1440
|
-
|
1441
|
-
|
1442
|
-
|
626
|
+
Adds a middleware and configuration options that can be used in your
|
627
|
+
application to automatically switch between the writing and reading
|
628
|
+
database connections.
|
1443
629
|
|
1444
|
-
|
630
|
+
`GET` and `HEAD` requests will read from the replica unless there was
|
631
|
+
a write in the last 2 seconds, otherwise they will read from the primary.
|
632
|
+
Non-get requests will always write to the primary. The middleware accepts
|
633
|
+
an argument for a Resolver class and an Operations class where you are able
|
634
|
+
to change how the auto-switcher works to be most beneficial for your
|
635
|
+
application.
|
1445
636
|
|
1446
|
-
|
1447
|
-
|
637
|
+
To use the middleware in your application you can use the following
|
638
|
+
configuration options:
|
1448
639
|
|
1449
|
-
|
640
|
+
```
|
641
|
+
config.active_record.database_selector = { delay: 2.seconds }
|
642
|
+
config.active_record.database_resolver = ActiveRecord::Middleware::DatabaseSelector::Resolver
|
643
|
+
config.active_record.database_resolver_context = ActiveRecord::Middleware::DatabaseSelector::Resolver::Session
|
644
|
+
```
|
1450
645
|
|
1451
|
-
|
646
|
+
To change the database selection strategy, pass a custom class to the
|
647
|
+
configuration options:
|
1452
648
|
|
1453
|
-
|
1454
|
-
|
1455
|
-
|
649
|
+
```
|
650
|
+
config.active_record.database_selector = { delay: 10.seconds }
|
651
|
+
config.active_record.database_resolver = MyResolver
|
652
|
+
config.active_record.database_resolver_context = MyResolver::MyCookies
|
653
|
+
```
|
1456
654
|
|
1457
|
-
*
|
655
|
+
*Eileen M. Uchitelle*
|
1458
656
|
|
1459
|
-
*
|
1460
|
-
extension names in PostgreSQL when migrating.
|
657
|
+
* MySQL: Support `:size` option to change text and blob size.
|
1461
658
|
|
1462
|
-
*
|
659
|
+
*Ryuta Kamizono*
|
1463
660
|
|
1464
|
-
*
|
1465
|
-
`references`, now works with any column types.
|
661
|
+
* Make `t.timestamps` with precision by default.
|
1466
662
|
|
1467
|
-
*
|
663
|
+
*Ryuta Kamizono*
|
1468
664
|
|
1469
|
-
* Add support for counter name to be passed as parameter on `CounterCache::ClassMethods#reset_counters`.
|
1470
665
|
|
1471
|
-
|
666
|
+
## Rails 6.0.0.beta1 (January 18, 2019) ##
|
1472
667
|
|
1473
|
-
*
|
1474
|
-
or `offset`.
|
668
|
+
* Remove deprecated `#set_state` from the transaction object.
|
1475
669
|
|
1476
|
-
|
1477
|
-
records to be deleted.
|
670
|
+
*Rafael Mendonça França*
|
1478
671
|
|
1479
|
-
|
672
|
+
* Remove deprecated `#supports_statement_cache?` from the database adapters.
|
1480
673
|
|
1481
|
-
*
|
674
|
+
*Rafael Mendonça França*
|
1482
675
|
|
1483
|
-
*
|
1484
|
-
their limit dropped from the schema.
|
676
|
+
* Remove deprecated `#insert_fixtures` from the database adapters.
|
1485
677
|
|
1486
|
-
|
678
|
+
*Rafael Mendonça França*
|
1487
679
|
|
1488
|
-
|
680
|
+
* Remove deprecated `ActiveRecord::ConnectionAdapters::SQLite3Adapter#valid_alter_table_type?`.
|
1489
681
|
|
1490
|
-
*
|
1491
|
-
association.
|
682
|
+
*Rafael Mendonça França*
|
1492
683
|
|
1493
|
-
|
684
|
+
* Do not allow passing the column name to `sum` when a block is passed.
|
1494
685
|
|
1495
|
-
*
|
686
|
+
*Rafael Mendonça França*
|
1496
687
|
|
1497
|
-
* `
|
1498
|
-
strings in column names as equal.
|
688
|
+
* Do not allow passing the column name to `count` when a block is passed.
|
1499
689
|
|
1500
|
-
|
1501
|
-
placeholders for them in the generated SQL statement, which can make PostgreSQL
|
1502
|
-
throw a `StatementInvalid` exception.
|
690
|
+
*Rafael Mendonça França*
|
1503
691
|
|
1504
|
-
|
692
|
+
* Remove delegation of missing methods in a relation to arel.
|
1505
693
|
|
1506
|
-
*
|
1507
|
-
attributes defined in parent classes.
|
694
|
+
*Rafael Mendonça França*
|
1508
695
|
|
1509
|
-
|
696
|
+
* Remove delegation of missing methods in a relation to private methods of the class.
|
1510
697
|
|
1511
|
-
*
|
698
|
+
*Rafael Mendonça França*
|
1512
699
|
|
1513
|
-
*
|
700
|
+
* Deprecate `config.active_record.sqlite3.represent_boolean_as_integer`.
|
1514
701
|
|
1515
|
-
|
702
|
+
*Rafael Mendonça França*
|
1516
703
|
|
1517
|
-
|
704
|
+
* Change `SQLite3Adapter` to always represent boolean values as integers.
|
1518
705
|
|
1519
|
-
*
|
706
|
+
*Rafael Mendonça França*
|
1520
707
|
|
1521
|
-
|
1522
|
-
PostgreSQL and are used by internal system catalogs. These field types
|
1523
|
-
can sometimes show up in structure-sniffing queries that feature internal system
|
1524
|
-
structures or with certain PostgreSQL extensions.
|
708
|
+
* Remove ability to specify a timestamp name for `#cache_key`.
|
1525
709
|
|
1526
|
-
*
|
710
|
+
*Rafael Mendonça França*
|
1527
711
|
|
1528
|
-
*
|
1529
|
-
NaN PostgreSQL values into a native Ruby `Float::INFINITY` and `Float::NAN`
|
712
|
+
* Remove deprecated `ActiveRecord::Migrator.migrations_path=`.
|
1530
713
|
|
1531
|
-
|
714
|
+
*Rafael Mendonça França*
|
1532
715
|
|
1533
|
-
|
1534
|
-
Point.last.value # => 0.0
|
716
|
+
* Remove deprecated `expand_hash_conditions_for_aggregates`.
|
1535
717
|
|
1536
|
-
|
718
|
+
*Rafael Mendonça França*
|
1537
719
|
|
1538
|
-
|
1539
|
-
Point.last.value # => Infinity
|
720
|
+
* Set polymorphic type column to NULL on `dependent: :nullify` strategy.
|
1540
721
|
|
1541
|
-
|
722
|
+
On polymorphic associations both the foreign key and the foreign type columns will be set to NULL.
|
1542
723
|
|
1543
|
-
*
|
724
|
+
*Laerti Papa*
|
1544
725
|
|
1545
|
-
|
726
|
+
* Allow permitted instance of `ActionController::Parameters` as argument of `ActiveRecord::Relation#exists?`.
|
1546
727
|
|
1547
|
-
*
|
728
|
+
*Gannon McGibbon*
|
1548
729
|
|
1549
|
-
*
|
1550
|
-
associations without replacement. These operations happen before instances
|
1551
|
-
are created. The current behavior is unexpected and can result in broken
|
1552
|
-
behavior.
|
730
|
+
* Add support for endless ranges introduces in Ruby 2.6.
|
1553
731
|
|
1554
|
-
|
732
|
+
*Greg Navis*
|
1555
733
|
|
1556
|
-
|
734
|
+
* Deprecate passing `migrations_paths` to `connection.assume_migrated_upto_version`.
|
1557
735
|
|
1558
|
-
*
|
736
|
+
*Ryuta Kamizono*
|
1559
737
|
|
1560
|
-
|
1561
|
-
size calculation if the collection is not cached or loaded.
|
738
|
+
* MySQL: `ROW_FORMAT=DYNAMIC` create table option by default.
|
1562
739
|
|
1563
|
-
|
740
|
+
Since MySQL 5.7.9, the `innodb_default_row_format` option defines the default row
|
741
|
+
format for InnoDB tables. The default setting is `DYNAMIC`.
|
742
|
+
The row format is required for indexing on `varchar(255)` with `utf8mb4` columns.
|
1564
743
|
|
1565
|
-
*
|
744
|
+
*Ryuta Kamizono*
|
1566
745
|
|
1567
|
-
*
|
1568
|
-
not exist.
|
746
|
+
* Fix join table column quoting with SQLite.
|
1569
747
|
|
1570
|
-
*
|
748
|
+
*Gannon McGibbon*
|
1571
749
|
|
1572
|
-
*
|
750
|
+
* Allow disabling scopes generated by `ActiveRecord.enum`.
|
1573
751
|
|
1574
|
-
|
1575
|
-
using namespaced models.
|
752
|
+
*Alfred Dominic*
|
1576
753
|
|
1577
|
-
|
754
|
+
* Ensure that `delete_all` on collection proxy returns affected count.
|
1578
755
|
|
1579
|
-
*
|
756
|
+
*Ryuta Kamizono*
|
1580
757
|
|
1581
|
-
|
1582
|
-
In 4.0 series it is delegated to `Array#join`.
|
758
|
+
* Reset scope after delete on collection association to clear stale offsets of removed records.
|
1583
759
|
|
1584
|
-
*
|
760
|
+
*Gannon McGibbon*
|
1585
761
|
|
1586
|
-
*
|
762
|
+
* Add the ability to prevent writes to a database for the duration of a block.
|
1587
763
|
|
1588
|
-
|
1589
|
-
|
1590
|
-
|
1591
|
-
that already has a non-nil value in that column since an initial nil
|
1592
|
-
value isn't included in the SQL anyway (at least, when dirty checking
|
1593
|
-
is enabled.) The column's new value will now be logged as `<NULL binary data>`
|
1594
|
-
to parallel the existing `<N bytes of binary data>` for non-nil values.
|
764
|
+
Allows the application to prevent writes to a database. This can be useful when
|
765
|
+
you're building out multiple databases and want to make sure you're not sending
|
766
|
+
writes when you want a read.
|
1595
767
|
|
1596
|
-
|
768
|
+
If `while_preventing_writes` is called and the query is considered a write
|
769
|
+
query the database will raise an exception regardless of whether the database
|
770
|
+
user is able to write.
|
1597
771
|
|
1598
|
-
|
1599
|
-
|
772
|
+
This is not meant to be a catch-all for write queries but rather a way to enforce
|
773
|
+
read-only queries without opening a second connection. One purpose of this is to
|
774
|
+
catch accidental writes, not all writes.
|
1600
775
|
|
1601
|
-
|
776
|
+
*Eileen M. Uchitelle*
|
1602
777
|
|
1603
|
-
|
778
|
+
* Allow aliased attributes to be used in `#update_columns` and `#update`.
|
1604
779
|
|
1605
|
-
*
|
780
|
+
*Gannon McGibbon*
|
1606
781
|
|
1607
|
-
|
1608
|
-
was ignored and overwritten by strict mode option.
|
782
|
+
* Allow spaces in postgres table names.
|
1609
783
|
|
1610
|
-
Fixes
|
784
|
+
Fixes issue where "user post" is misinterpreted as "\"user\".\"post\"" when quoting table names with the postgres adapter.
|
1611
785
|
|
1612
|
-
*
|
786
|
+
*Gannon McGibbon*
|
1613
787
|
|
1614
|
-
*
|
788
|
+
* Cached `columns_hash` fields should be excluded from `ResultSet#column_types`.
|
1615
789
|
|
1616
|
-
|
790
|
+
PR #34528 addresses the inconsistent behaviour when attribute is defined for an ignored column. The following test
|
791
|
+
was passing for SQLite and MySQL, but failed for PostgreSQL:
|
1617
792
|
|
1618
|
-
|
793
|
+
```ruby
|
794
|
+
class DeveloperName < ActiveRecord::Type::String
|
795
|
+
def deserialize(value)
|
796
|
+
"Developer: #{value}"
|
797
|
+
end
|
798
|
+
end
|
1619
799
|
|
1620
|
-
|
800
|
+
class AttributedDeveloper < ActiveRecord::Base
|
801
|
+
self.table_name = "developers"
|
1621
802
|
|
1622
|
-
|
803
|
+
attribute :name, DeveloperName.new
|
1623
804
|
|
1624
|
-
|
1625
|
-
|
1626
|
-
uses the reflections to set database with fixtures.
|
805
|
+
self.ignored_columns += ["name"]
|
806
|
+
end
|
1627
807
|
|
1628
|
-
|
808
|
+
developer = AttributedDeveloper.create
|
809
|
+
developer.update_column :name, "name"
|
1629
810
|
|
1630
|
-
|
811
|
+
loaded_developer = AttributedDeveloper.where(id: developer.id).select("*").first
|
812
|
+
puts loaded_developer.name # should be "Developer: name" but it's just "name"
|
813
|
+
```
|
1631
814
|
|
1632
|
-
*
|
1633
|
-
Additionally display a warning message to make the user aware.
|
815
|
+
*Dmitry Tsepelev*
|
1634
816
|
|
1635
|
-
|
817
|
+
* Make the implicit order column configurable.
|
1636
818
|
|
1637
|
-
|
1638
|
-
|
819
|
+
When calling ordered finder methods such as `first` or `last` without an
|
820
|
+
explicit order clause, ActiveRecord sorts records by primary key. This can
|
821
|
+
result in unpredictable and surprising behaviour when the primary key is
|
822
|
+
not an auto-incrementing integer, for example when it's a UUID. This change
|
823
|
+
makes it possible to override the column used for implicit ordering such
|
824
|
+
that `first` and `last` will return more predictable results.
|
1639
825
|
|
1640
826
|
Example:
|
1641
827
|
|
1642
|
-
|
1643
|
-
|
1644
|
-
|
1645
|
-
# => also :datetime (previously would be :timestamp)
|
1646
|
-
|
1647
|
-
See #14513.
|
1648
|
-
|
1649
|
-
*Jefferson Lai*
|
1650
|
-
|
1651
|
-
* `ActiveRecord::Base.no_touching` no longer triggers callbacks or start empty transactions.
|
1652
|
-
|
1653
|
-
Fixes #14841.
|
1654
|
-
|
1655
|
-
*Lucas Mazza*
|
1656
|
-
|
1657
|
-
* Fix name collision with `Array#select!` with `Relation#select!`.
|
1658
|
-
|
1659
|
-
Fixes #14752.
|
1660
|
-
|
1661
|
-
*Earl St Sauver*
|
828
|
+
class Project < ActiveRecord::Base
|
829
|
+
self.implicit_order_column = "created_at"
|
830
|
+
end
|
1662
831
|
|
1663
|
-
*
|
1664
|
-
a scoped `has_many`.
|
832
|
+
*Tekin Suleyman*
|
1665
833
|
|
1666
|
-
|
1667
|
-
`has_many :through` uses this association, then the scope adjustment is
|
1668
|
-
unexpectedly neglected.
|
834
|
+
* Bump minimum PostgreSQL version to 9.3.
|
1669
835
|
|
1670
|
-
|
836
|
+
*Yasuo Honda*
|
1671
837
|
|
1672
|
-
|
838
|
+
* Values of enum are frozen, raising an error when attempting to modify them.
|
1673
839
|
|
1674
|
-
*
|
840
|
+
*Emmanuel Byrd*
|
1675
841
|
|
1676
|
-
|
842
|
+
* Move `ActiveRecord::StatementInvalid` SQL to error property and include binds as separate error property.
|
1677
843
|
|
1678
|
-
|
844
|
+
`ActiveRecord::ConnectionAdapters::AbstractAdapter#translate_exception_class` now requires `binds` to be passed as the last argument.
|
1679
845
|
|
1680
|
-
|
846
|
+
`ActiveRecord::ConnectionAdapters::AbstractAdapter#translate_exception` now requires `message`, `sql`, and `binds` to be passed as keyword arguments.
|
1681
847
|
|
1682
|
-
|
848
|
+
Subclasses of `ActiveRecord::StatementInvalid` must now provide `sql:` and `binds:` arguments to `super`.
|
1683
849
|
|
1684
|
-
|
850
|
+
Example:
|
1685
851
|
|
1686
|
-
|
852
|
+
```
|
853
|
+
class MySubclassedError < ActiveRecord::StatementInvalid
|
854
|
+
def initialize(message, sql:, binds:)
|
855
|
+
super(message, sql: sql, binds: binds)
|
856
|
+
end
|
857
|
+
end
|
858
|
+
```
|
1687
859
|
|
1688
|
-
*
|
860
|
+
*Gannon McGibbon*
|
1689
861
|
|
1690
|
-
* `
|
1691
|
-
LIKE statement.
|
862
|
+
* Add an `:if_not_exists` option to `create_table`.
|
1692
863
|
|
1693
864
|
Example:
|
1694
865
|
|
1695
|
-
|
1696
|
-
|
1697
|
-
where("title LIKE ?", sanitize_sql_like(term))
|
1698
|
-
end
|
866
|
+
create_table :posts, if_not_exists: true do |t|
|
867
|
+
t.string :title
|
1699
868
|
end
|
1700
869
|
|
1701
|
-
|
1702
|
-
# => Query looks like "... title LIKE '20\% \_reduction\_' ..."
|
1703
|
-
|
1704
|
-
*Rob Gilson*, *Yves Senn*
|
870
|
+
That would execute:
|
1705
871
|
|
1706
|
-
|
872
|
+
CREATE TABLE IF NOT EXISTS posts (
|
873
|
+
...
|
874
|
+
)
|
1707
875
|
|
1708
|
-
|
876
|
+
If the table already exists, `if_not_exists: false` (the default) raises an
|
877
|
+
exception whereas `if_not_exists: true` does nothing.
|
1709
878
|
|
1710
|
-
*
|
879
|
+
*fatkodima*, *Stefan Kanev*
|
1711
880
|
|
1712
|
-
*
|
881
|
+
* Defining an Enum as a Hash with blank key, or as an Array with a blank value, now raises an `ArgumentError`.
|
1713
882
|
|
1714
|
-
|
883
|
+
*Christophe Maximin*
|
1715
884
|
|
1716
|
-
|
1717
|
-
# => true
|
1718
|
-
Post.where(author_id: author.id) == author.posts
|
1719
|
-
# => true
|
885
|
+
* Adds support for multiple databases to `rails db:schema:cache:dump` and `rails db:schema:cache:clear`.
|
1720
886
|
|
1721
|
-
|
887
|
+
*Gannon McGibbon*
|
1722
888
|
|
1723
|
-
|
889
|
+
* `update_columns` now correctly raises `ActiveModel::MissingAttributeError`
|
890
|
+
if the attribute does not exist.
|
1724
891
|
|
1725
|
-
*
|
1726
|
-
generates an SQL statement containing each id of the collection:
|
892
|
+
*Sean Griffin*
|
1727
893
|
|
1728
|
-
|
894
|
+
* Add support for hash and URL configs in database hash of `ActiveRecord::Base.connected_to`.
|
1729
895
|
|
1730
|
-
|
1731
|
-
|
896
|
+
````
|
897
|
+
User.connected_to(database: { writing: "postgres://foo" }) do
|
898
|
+
User.create!(name: "Gannon")
|
899
|
+
end
|
1732
900
|
|
1733
|
-
|
901
|
+
config = { "adapter" => "sqlite3", "database" => "db/readonly.sqlite3" }
|
902
|
+
User.connected_to(database: { reading: config }) do
|
903
|
+
User.count
|
904
|
+
end
|
905
|
+
````
|
1734
906
|
|
1735
|
-
|
907
|
+
*Gannon McGibbon*
|
1736
908
|
|
1737
|
-
|
909
|
+
* Support default expression for MySQL.
|
1738
910
|
|
1739
|
-
|
1740
|
-
with `select`.
|
911
|
+
MySQL 8.0.13 and higher supports default value to be a function or expression.
|
1741
912
|
|
1742
|
-
|
913
|
+
https://dev.mysql.com/doc/refman/8.0/en/create-table.html
|
1743
914
|
|
1744
|
-
*
|
915
|
+
*Ryuta Kamizono*
|
1745
916
|
|
1746
|
-
*
|
917
|
+
* Support expression indexes for MySQL.
|
1747
918
|
|
1748
|
-
|
919
|
+
MySQL 8.0.13 and higher supports functional key parts that index
|
920
|
+
expression values rather than column or column prefix values.
|
1749
921
|
|
1750
|
-
|
922
|
+
https://dev.mysql.com/doc/refman/8.0/en/create-index.html
|
1751
923
|
|
1752
|
-
*
|
1753
|
-
unknown OIDs.
|
924
|
+
*Ryuta Kamizono*
|
1754
925
|
|
1755
|
-
|
926
|
+
* Fix collection cache key with limit and custom select to avoid ambiguous timestamp column error.
|
1756
927
|
|
1757
|
-
|
928
|
+
Fixes #33056.
|
1758
929
|
|
1759
|
-
*
|
930
|
+
*Federico Martinez*
|
1760
931
|
|
1761
|
-
|
932
|
+
* Add basic API for connection switching to support multiple databases.
|
1762
933
|
|
1763
|
-
|
934
|
+
1) Adds a `connects_to` method for models to connect to multiple databases. Example:
|
1764
935
|
|
1765
|
-
|
936
|
+
```
|
937
|
+
class AnimalsModel < ApplicationRecord
|
938
|
+
self.abstract_class = true
|
1766
939
|
|
1767
|
-
|
940
|
+
connects_to database: { writing: :animals_primary, reading: :animals_replica }
|
941
|
+
end
|
1768
942
|
|
1769
|
-
|
943
|
+
class Dog < AnimalsModel
|
944
|
+
# connected to both the animals_primary db for writing and the animals_replica for reading
|
945
|
+
end
|
946
|
+
```
|
1770
947
|
|
1771
|
-
|
1772
|
-
|
948
|
+
2) Adds a `connected_to` block method for switching connection roles or connecting to
|
949
|
+
a database that the model didn't connect to. Connecting to the database in this block is
|
950
|
+
useful when you have another defined connection, for example `slow_replica` that you don't
|
951
|
+
want to connect to by default but need in the console, or a specific code block.
|
1773
952
|
|
1774
|
-
|
953
|
+
```
|
954
|
+
ActiveRecord::Base.connected_to(role: :reading) do
|
955
|
+
Dog.first # finds dog from replica connected to AnimalsBase
|
956
|
+
Book.first # doesn't have a reading connection, will raise an error
|
957
|
+
end
|
958
|
+
```
|
1775
959
|
|
1776
|
-
|
960
|
+
```
|
961
|
+
ActiveRecord::Base.connected_to(database: :slow_replica) do
|
962
|
+
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
|
963
|
+
end
|
964
|
+
```
|
1777
965
|
|
1778
|
-
*
|
966
|
+
*Eileen M. Uchitelle*
|
1779
967
|
|
1780
|
-
|
968
|
+
* Enum raises on invalid definition values
|
1781
969
|
|
1782
|
-
|
970
|
+
When defining a Hash enum it can be easy to use `[]` instead of `{}`. This
|
971
|
+
commit checks that only valid definition values are provided, those can
|
972
|
+
be a Hash, an array of Symbols or an array of Strings. Otherwise it
|
973
|
+
raises an `ArgumentError`.
|
1783
974
|
|
1784
|
-
|
975
|
+
Fixes #33961
|
1785
976
|
|
1786
|
-
|
977
|
+
*Alberto Almagro*
|
1787
978
|
|
1788
|
-
|
979
|
+
* Reloading associations now clears the Query Cache like `Persistence#reload` does.
|
1789
980
|
|
1790
|
-
|
1791
|
-
|
1792
|
-
|
1793
|
-
|
981
|
+
```
|
982
|
+
class Post < ActiveRecord::Base
|
983
|
+
has_one :category
|
984
|
+
belongs_to :author
|
985
|
+
has_many :comments
|
986
|
+
end
|
1794
987
|
|
1795
|
-
|
988
|
+
# Each of the following will now clear the query cache.
|
989
|
+
post.reload_category
|
990
|
+
post.reload_author
|
991
|
+
post.comments.reload
|
992
|
+
```
|
1796
993
|
|
1797
|
-
*
|
994
|
+
*Christophe Maximin*
|
1798
995
|
|
1799
|
-
*
|
996
|
+
* Added `index` option for `change_table` migration helpers.
|
997
|
+
With this change you can create indexes while adding new
|
998
|
+
columns into the existing tables.
|
1800
999
|
|
1801
|
-
|
1000
|
+
Example:
|
1802
1001
|
|
1803
|
-
|
1002
|
+
change_table(:languages) do |t|
|
1003
|
+
t.string :country_code, index: true
|
1004
|
+
end
|
1804
1005
|
|
1805
|
-
*
|
1006
|
+
*Mehmet Emin İNAÇ*
|
1806
1007
|
|
1807
|
-
* Fix
|
1008
|
+
* Fix `transaction` reverting for migrations.
|
1808
1009
|
|
1809
|
-
|
1010
|
+
Before: Commands inside a `transaction` in a reverted migration ran uninverted.
|
1011
|
+
Now: This change fixes that by reverting commands inside `transaction` block.
|
1810
1012
|
|
1811
|
-
*
|
1013
|
+
*fatkodima*, *David Verhasselt*
|
1812
1014
|
|
1813
|
-
*
|
1814
|
-
deprecated in 4.1) from relative to absolute.
|
1015
|
+
* Raise an error instead of scanning the filesystem root when `fixture_path` is blank.
|
1815
1016
|
|
1816
|
-
|
1817
|
-
`sqlite3:///my/path` with `sqlite3:my/path`.
|
1017
|
+
*Gannon McGibbon*, *Max Albrecht*
|
1818
1018
|
|
1819
|
-
|
1019
|
+
* Allow `ActiveRecord::Base.configurations=` to be set with a symbolized hash.
|
1820
1020
|
|
1821
|
-
*
|
1021
|
+
*Gannon McGibbon*
|
1822
1022
|
|
1823
|
-
|
1023
|
+
* Don't update counter cache unless the record is actually saved.
|
1824
1024
|
|
1825
|
-
|
1025
|
+
Fixes #31493, #33113, #33117.
|
1826
1026
|
|
1827
|
-
*
|
1027
|
+
*Ryuta Kamizono*
|
1828
1028
|
|
1829
|
-
*
|
1029
|
+
* Deprecate `ActiveRecord::Result#to_hash` in favor of `ActiveRecord::Result#to_a`.
|
1830
1030
|
|
1831
|
-
*
|
1031
|
+
*Gannon McGibbon*, *Kevin Cheng*
|
1832
1032
|
|
1833
|
-
*
|
1033
|
+
* SQLite3 adapter supports expression indexes.
|
1834
1034
|
|
1835
|
-
|
1035
|
+
```
|
1036
|
+
create_table :users do |t|
|
1037
|
+
t.string :email
|
1038
|
+
end
|
1836
1039
|
|
1837
|
-
|
1838
|
-
|
1839
|
-
`nil` as type but `enum`.
|
1040
|
+
add_index :users, 'lower(email)', name: 'index_users_on_email', unique: true
|
1041
|
+
```
|
1840
1042
|
|
1841
|
-
|
1043
|
+
*Gray Kemmey*
|
1842
1044
|
|
1843
|
-
|
1045
|
+
* Allow subclasses to redefine autosave callbacks for associated records.
|
1844
1046
|
|
1845
|
-
|
1846
|
-
column.
|
1047
|
+
Fixes #33305.
|
1847
1048
|
|
1848
|
-
|
1049
|
+
*Andrey Subbota*
|
1849
1050
|
|
1850
|
-
|
1051
|
+
* Bump minimum MySQL version to 5.5.8.
|
1851
1052
|
|
1852
|
-
*
|
1853
|
-
custom primary key that did not save due to validation error.
|
1053
|
+
*Yasuo Honda*
|
1854
1054
|
|
1855
|
-
|
1055
|
+
* Use MySQL utf8mb4 character set by default.
|
1856
1056
|
|
1857
|
-
|
1057
|
+
`utf8mb4` character set with 4-Byte encoding supports supplementary characters including emoji.
|
1058
|
+
The previous default 3-Byte encoding character set `utf8` is not enough to support them.
|
1858
1059
|
|
1859
|
-
*
|
1060
|
+
*Yasuo Honda*
|
1860
1061
|
|
1861
|
-
|
1062
|
+
* Fix duplicated record creation when using nested attributes with `create_with`.
|
1862
1063
|
|
1863
|
-
*
|
1064
|
+
*Darwin Wu*
|
1864
1065
|
|
1865
|
-
*
|
1066
|
+
* Configuration item `config.filter_parameters` could also filter out
|
1067
|
+
sensitive values of database columns when calling `#inspect`.
|
1068
|
+
We also added `ActiveRecord::Base::filter_attributes`/`=` in order to
|
1069
|
+
specify sensitive attributes to specific model.
|
1866
1070
|
|
1867
|
-
|
1868
|
-
|
1071
|
+
```
|
1072
|
+
Rails.application.config.filter_parameters += [:credit_card_number, /phone/]
|
1073
|
+
Account.last.inspect # => #<Account id: 123, name: "DHH", credit_card_number: [FILTERED], telephone_number: [FILTERED] ...>
|
1074
|
+
SecureAccount.filter_attributes += [:name]
|
1075
|
+
SecureAccount.last.inspect # => #<SecureAccount id: 42, name: [FILTERED], credit_card_number: [FILTERED] ...>
|
1076
|
+
```
|
1869
1077
|
|
1870
|
-
|
1871
|
-
required.
|
1078
|
+
*Zhang Kang*, *Yoshiyuki Kinjo*
|
1872
1079
|
|
1873
|
-
|
1080
|
+
* Deprecate `column_name_length`, `table_name_length`, `columns_per_table`,
|
1081
|
+
`indexes_per_table`, `columns_per_multicolumn_index`, `sql_query_length`,
|
1082
|
+
and `joins_per_query` methods in `DatabaseLimits`.
|
1874
1083
|
|
1875
|
-
|
1876
|
-
t.index :zip
|
1877
|
-
end
|
1878
|
-
# => CREATE TEMPORARY TABLE temp (INDEX (zip)) AS SELECT id, name, zip FROM a_really_complicated_query
|
1879
|
-
|
1880
|
-
*Cody Cutrer*, *Steve Rice*, *Rafael Mendonça Franca*
|
1881
|
-
|
1882
|
-
* Use singular table name in generated migrations when
|
1883
|
-
`ActiveRecord::Base.pluralize_table_names` is `false`.
|
1084
|
+
*Ryuta Kamizono*
|
1884
1085
|
|
1885
|
-
|
1086
|
+
* `ActiveRecord::Base.configurations` now returns an object.
|
1886
1087
|
|
1887
|
-
|
1088
|
+
`ActiveRecord::Base.configurations` used to return a hash, but this
|
1089
|
+
is an inflexible data model. In order to improve multiple-database
|
1090
|
+
handling in Rails, we've changed this to return an object. Some methods
|
1091
|
+
are provided to make the object behave hash-like in order to ease the
|
1092
|
+
transition process. Since most applications don't manipulate the hash
|
1093
|
+
we've decided to add backwards-compatible functionality that will throw
|
1094
|
+
a deprecation warning if used, however calling `ActiveRecord::Base.configurations`
|
1095
|
+
will use the new version internally and externally.
|
1888
1096
|
|
1889
|
-
|
1097
|
+
For example, the following `database.yml`:
|
1890
1098
|
|
1891
|
-
|
1099
|
+
```
|
1100
|
+
development:
|
1101
|
+
adapter: sqlite3
|
1102
|
+
database: db/development.sqlite3
|
1103
|
+
```
|
1892
1104
|
|
1893
|
-
|
1894
|
-
Photo.last.touch(:signed_at, :sealed_at)
|
1105
|
+
Used to become a hash:
|
1895
1106
|
|
1896
|
-
|
1107
|
+
```
|
1108
|
+
{ "development" => { "adapter" => "sqlite3", "database" => "db/development.sqlite3" } }
|
1109
|
+
```
|
1897
1110
|
|
1898
|
-
|
1899
|
-
migration table exists.
|
1111
|
+
Is now converted into the following object:
|
1900
1112
|
|
1901
|
-
|
1113
|
+
```
|
1114
|
+
#<ActiveRecord::DatabaseConfigurations:0x00007fd1acbdf800 @configurations=[
|
1115
|
+
#<ActiveRecord::DatabaseConfigurations::HashConfig:0x00007fd1acbded10 @env_name="development",
|
1116
|
+
@spec_name="primary", @config={"adapter"=>"sqlite3", "database"=>"db/development.sqlite3"}>
|
1117
|
+
]
|
1118
|
+
```
|
1902
1119
|
|
1903
|
-
|
1120
|
+
Iterating over the database configurations has also changed. Instead of
|
1121
|
+
calling hash methods on the `configurations` hash directly, a new method `configs_for` has
|
1122
|
+
been provided that allows you to select the correct configuration. `env_name` and
|
1123
|
+
`spec_name` arguments are optional. For example, these return an array of
|
1124
|
+
database config objects for the requested environment and a single database config object
|
1125
|
+
will be returned for the requested environment and specification name respectively.
|
1904
1126
|
|
1905
|
-
|
1906
|
-
|
1907
|
-
|
1908
|
-
|
1909
|
-
the same time.
|
1127
|
+
```
|
1128
|
+
ActiveRecord::Base.configurations.configs_for(env_name: "development")
|
1129
|
+
ActiveRecord::Base.configurations.configs_for(env_name: "development", spec_name: "primary")
|
1130
|
+
```
|
1910
1131
|
|
1911
|
-
*
|
1132
|
+
*Eileen M. Uchitelle*, *Aaron Patterson*
|
1912
1133
|
|
1913
|
-
*
|
1914
|
-
pointing to pg_class, and thus only sequence objects, are considered.
|
1134
|
+
* Add database configuration to disable advisory locks.
|
1915
1135
|
|
1916
|
-
|
1136
|
+
```
|
1137
|
+
production:
|
1138
|
+
adapter: postgresql
|
1139
|
+
advisory_locks: false
|
1140
|
+
```
|
1917
1141
|
|
1918
|
-
*
|
1142
|
+
*Guo Xiang*
|
1919
1143
|
|
1920
|
-
|
1144
|
+
* SQLite3 adapter `alter_table` method restores foreign keys.
|
1921
1145
|
|
1922
|
-
*
|
1146
|
+
*Yasuo Honda*
|
1923
1147
|
|
1924
|
-
*
|
1148
|
+
* Allow `:to_table` option to `invert_remove_foreign_key`.
|
1925
1149
|
|
1926
1150
|
Example:
|
1927
1151
|
|
1928
|
-
|
1929
|
-
email: $LABEL@email.com
|
1930
|
-
|
1931
|
-
users(:martin).email # => martin@email.com
|
1152
|
+
remove_foreign_key :accounts, to_table: :owners
|
1932
1153
|
|
1933
|
-
*
|
1154
|
+
*Nikolay Epifanov*, *Rich Chen*
|
1934
1155
|
|
1935
|
-
* Add
|
1156
|
+
* Add environment & load_config dependency to `bin/rake db:seed` to enable
|
1157
|
+
seed load in environments without Rails and custom DB configuration
|
1936
1158
|
|
1937
|
-
|
1938
|
-
|
1939
|
-
*arthurnn*
|
1159
|
+
*Tobias Bielohlawek*
|
1940
1160
|
|
1941
|
-
*
|
1942
|
-
Call `.id` on the object first.
|
1161
|
+
* Fix default value for mysql time types with specified precision.
|
1943
1162
|
|
1944
|
-
*
|
1163
|
+
*Nikolay Kondratyev*
|
1945
1164
|
|
1946
|
-
*
|
1947
|
-
has a case insensitive collation.
|
1165
|
+
* Fix `touch` option to behave consistently with `Persistence#touch` method.
|
1948
1166
|
|
1949
1167
|
*Ryuta Kamizono*
|
1950
1168
|
|
1951
|
-
*
|
1169
|
+
* Migrations raise when duplicate column definition.
|
1952
1170
|
|
1953
|
-
|
1171
|
+
Fixes #33024.
|
1954
1172
|
|
1955
|
-
*
|
1956
|
-
`where` values without needing to wrap in UPPER/LOWER sql functions.
|
1173
|
+
*Federico Martinez*
|
1957
1174
|
|
1958
|
-
|
1175
|
+
* Bump minimum SQLite version to 3.8
|
1959
1176
|
|
1960
|
-
*
|
1961
|
-
Previously after save related callbacks, such as `#after_commit`, were triggered when the has_one
|
1962
|
-
object did not get saved to the db.
|
1177
|
+
*Yasuo Honda*
|
1963
1178
|
|
1964
|
-
|
1179
|
+
* Fix parent record should not get saved with duplicate children records.
|
1965
1180
|
|
1966
|
-
|
1967
|
-
|
1968
|
-
Example:
|
1181
|
+
Fixes #32940.
|
1969
1182
|
|
1970
|
-
|
1183
|
+
*Santosh Wadghule*
|
1971
1184
|
|
1972
|
-
|
1185
|
+
* Fix logic on disabling commit callbacks so they are not called unexpectedly when errors occur.
|
1973
1186
|
|
1974
|
-
*
|
1975
|
-
warnings on enum columns.
|
1187
|
+
*Brian Durand*
|
1976
1188
|
|
1977
|
-
|
1189
|
+
* Ensure `Associations::CollectionAssociation#size` and `Associations::CollectionAssociation#empty?`
|
1190
|
+
use loaded association ids if present.
|
1978
1191
|
|
1979
|
-
*
|
1980
|
-
joins are involved.
|
1192
|
+
*Graham Turner*
|
1981
1193
|
|
1982
|
-
|
1194
|
+
* Add support to preload associations of polymorphic associations when not all the records have the requested associations.
|
1983
1195
|
|
1984
|
-
*
|
1196
|
+
*Dana Sherson*
|
1985
1197
|
|
1986
|
-
*
|
1987
|
-
any enum attribute is always evaluated as 0 during uniqueness validation.
|
1198
|
+
* Add `touch_all` method to `ActiveRecord::Relation`.
|
1988
1199
|
|
1989
|
-
|
1200
|
+
Example:
|
1990
1201
|
|
1991
|
-
|
1202
|
+
Person.where(name: "David").touch_all(time: Time.new(2020, 5, 16, 0, 0, 0))
|
1992
1203
|
|
1993
|
-
*
|
1994
|
-
`has_and_belongs_to_many` associations *and* on `has_many :through`
|
1995
|
-
associations. Before this change, `before_add` callbacks would be fired
|
1996
|
-
before the record was saved on `has_and_belongs_to_many` associations, but
|
1997
|
-
*not* on `has_many :through` associations.
|
1204
|
+
*fatkodima*, *duggiefresh*
|
1998
1205
|
|
1999
|
-
|
1206
|
+
* Add `ActiveRecord::Base.base_class?` predicate.
|
2000
1207
|
|
2001
|
-
*
|
2002
|
-
private method defined on its ancestors.
|
1208
|
+
*Bogdan Gusiev*
|
2003
1209
|
|
2004
|
-
|
1210
|
+
* Add custom prefix/suffix options to `ActiveRecord::Store.store_accessor`.
|
2005
1211
|
|
2006
|
-
*
|
1212
|
+
*Tan Huynh*, *Yukio Mizuta*
|
2007
1213
|
|
2008
|
-
*
|
1214
|
+
* Rails 6 requires Ruby 2.5.0 or newer.
|
2009
1215
|
|
2010
|
-
|
1216
|
+
*Jeremy Daer*, *Kasper Timm Hansen*
|
2011
1217
|
|
2012
|
-
|
2013
|
-
book.save!
|
2014
|
-
book.title # => "12345"
|
1218
|
+
* Deprecate `update_attributes`/`!` in favor of `update`/`!`.
|
2015
1219
|
|
2016
|
-
*
|
1220
|
+
*Eddie Lebow*
|
2017
1221
|
|
2018
|
-
*
|
2019
|
-
|
2020
|
-
possible because the Ruby range does not support excluded beginnings.
|
1222
|
+
* Add `ActiveRecord::Base.create_or_find_by`/`!` to deal with the SELECT/INSERT race condition in
|
1223
|
+
`ActiveRecord::Base.find_or_create_by`/`!` by leaning on unique constraints in the database.
|
2021
1224
|
|
2022
|
-
|
2023
|
-
deprecated. For subtypes where we don't know how to increment (e.g. `#succ`
|
2024
|
-
is not defined) it will raise an `ArgumentException` for ranges with excluding
|
2025
|
-
beginnings.
|
1225
|
+
*DHH*
|
2026
1226
|
|
2027
|
-
|
1227
|
+
* Add `Relation#pick` as short-hand for single-value plucks.
|
2028
1228
|
|
2029
|
-
*
|
1229
|
+
*DHH*
|
2030
1230
|
|
2031
|
-
*Yves Senn*
|
2032
1231
|
|
2033
|
-
Please check [
|
1232
|
+
Please check [5-2-stable](https://github.com/rails/rails/blob/5-2-stable/activerecord/CHANGELOG.md) for previous changes.
|