activerecord 5.2.6 → 6.0.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 +928 -559
- data/MIT-LICENSE +3 -1
- data/README.rdoc +5 -3
- data/examples/performance.rb +1 -1
- data/lib/active_record/advisory_lock_base.rb +18 -0
- data/lib/active_record/aggregations.rb +4 -3
- data/lib/active_record/association_relation.rb +10 -8
- data/lib/active_record/associations/alias_tracker.rb +0 -1
- data/lib/active_record/associations/association.rb +55 -19
- data/lib/active_record/associations/association_scope.rb +11 -7
- data/lib/active_record/associations/belongs_to_association.rb +36 -42
- data/lib/active_record/associations/belongs_to_polymorphic_association.rb +0 -4
- data/lib/active_record/associations/builder/association.rb +14 -18
- data/lib/active_record/associations/builder/belongs_to.rb +19 -52
- data/lib/active_record/associations/builder/collection_association.rb +3 -13
- data/lib/active_record/associations/builder/has_and_belongs_to_many.rb +17 -40
- data/lib/active_record/associations/builder/has_many.rb +2 -0
- data/lib/active_record/associations/builder/has_one.rb +35 -1
- data/lib/active_record/associations/builder/singular_association.rb +2 -0
- data/lib/active_record/associations/collection_association.rb +19 -23
- data/lib/active_record/associations/collection_proxy.rb +14 -17
- data/lib/active_record/associations/foreign_association.rb +7 -0
- data/lib/active_record/associations/has_many_association.rb +2 -11
- data/lib/active_record/associations/has_many_through_association.rb +14 -14
- data/lib/active_record/associations/has_one_association.rb +28 -30
- data/lib/active_record/associations/has_one_through_association.rb +5 -5
- data/lib/active_record/associations/join_dependency/join_association.rb +16 -10
- data/lib/active_record/associations/join_dependency/join_part.rb +4 -4
- data/lib/active_record/associations/join_dependency.rb +47 -30
- data/lib/active_record/associations/preloader/association.rb +61 -41
- data/lib/active_record/associations/preloader/through_association.rb +48 -39
- data/lib/active_record/associations/preloader.rb +44 -33
- data/lib/active_record/associations/singular_association.rb +2 -16
- data/lib/active_record/associations/through_association.rb +1 -1
- data/lib/active_record/associations.rb +21 -16
- data/lib/active_record/attribute_assignment.rb +7 -11
- data/lib/active_record/attribute_decorators.rb +0 -2
- data/lib/active_record/attribute_methods/before_type_cast.rb +4 -2
- data/lib/active_record/attribute_methods/dirty.rb +111 -40
- data/lib/active_record/attribute_methods/primary_key.rb +15 -24
- data/lib/active_record/attribute_methods/query.rb +2 -3
- data/lib/active_record/attribute_methods/read.rb +15 -54
- data/lib/active_record/attribute_methods/serialization.rb +1 -2
- data/lib/active_record/attribute_methods/time_zone_conversion.rb +1 -3
- data/lib/active_record/attribute_methods/write.rb +17 -25
- data/lib/active_record/attribute_methods.rb +28 -100
- data/lib/active_record/attributes.rb +13 -1
- data/lib/active_record/autosave_association.rb +12 -14
- data/lib/active_record/base.rb +2 -3
- data/lib/active_record/callbacks.rb +6 -21
- data/lib/active_record/coders/yaml_column.rb +0 -1
- data/lib/active_record/connection_adapters/abstract/connection_pool.rb +109 -18
- data/lib/active_record/connection_adapters/abstract/database_limits.rb +17 -4
- data/lib/active_record/connection_adapters/abstract/database_statements.rb +102 -124
- data/lib/active_record/connection_adapters/abstract/query_cache.rb +18 -9
- data/lib/active_record/connection_adapters/abstract/quoting.rb +68 -17
- data/lib/active_record/connection_adapters/abstract/schema_creation.rb +20 -14
- data/lib/active_record/connection_adapters/abstract/schema_definitions.rb +105 -72
- data/lib/active_record/connection_adapters/abstract/schema_dumper.rb +1 -3
- data/lib/active_record/connection_adapters/abstract/schema_statements.rb +175 -79
- data/lib/active_record/connection_adapters/abstract/transaction.rb +96 -57
- data/lib/active_record/connection_adapters/abstract_adapter.rb +197 -43
- data/lib/active_record/connection_adapters/abstract_mysql_adapter.rb +149 -217
- data/lib/active_record/connection_adapters/column.rb +17 -13
- data/lib/active_record/connection_adapters/connection_specification.rb +54 -45
- data/lib/active_record/connection_adapters/determine_if_preparable_visitor.rb +6 -10
- data/lib/active_record/connection_adapters/mysql/column.rb +1 -1
- data/lib/active_record/connection_adapters/mysql/database_statements.rb +70 -14
- data/lib/active_record/connection_adapters/mysql/explain_pretty_printer.rb +0 -1
- data/lib/active_record/connection_adapters/mysql/quoting.rb +44 -7
- data/lib/active_record/connection_adapters/mysql/schema_creation.rb +4 -6
- data/lib/active_record/connection_adapters/mysql/schema_definitions.rb +40 -32
- data/lib/active_record/connection_adapters/mysql/schema_dumper.rb +14 -6
- data/lib/active_record/connection_adapters/mysql/schema_statements.rb +139 -19
- data/lib/active_record/connection_adapters/mysql/type_metadata.rb +6 -10
- data/lib/active_record/connection_adapters/mysql2_adapter.rb +26 -10
- data/lib/active_record/connection_adapters/postgresql/column.rb +17 -31
- data/lib/active_record/connection_adapters/postgresql/database_statements.rb +26 -1
- data/lib/active_record/connection_adapters/postgresql/oid/array.rb +1 -2
- data/lib/active_record/connection_adapters/postgresql/oid/bit.rb +1 -4
- data/lib/active_record/connection_adapters/postgresql/oid/date_time.rb +8 -0
- data/lib/active_record/connection_adapters/postgresql/oid/enum.rb +0 -1
- data/lib/active_record/connection_adapters/postgresql/oid/hstore.rb +1 -2
- data/lib/active_record/connection_adapters/postgresql/oid/legacy_point.rb +1 -2
- data/lib/active_record/connection_adapters/postgresql/oid/oid.rb +1 -1
- data/lib/active_record/connection_adapters/postgresql/oid/point.rb +1 -2
- data/lib/active_record/connection_adapters/postgresql/oid/range.rb +25 -7
- data/lib/active_record/connection_adapters/postgresql/oid/specialized_string.rb +1 -1
- data/lib/active_record/connection_adapters/postgresql/oid/type_map_initializer.rb +9 -7
- data/lib/active_record/connection_adapters/postgresql/oid/uuid.rb +5 -3
- data/lib/active_record/connection_adapters/postgresql/quoting.rb +44 -7
- data/lib/active_record/connection_adapters/postgresql/referential_integrity.rb +1 -1
- data/lib/active_record/connection_adapters/postgresql/schema_creation.rb +14 -3
- data/lib/active_record/connection_adapters/postgresql/schema_definitions.rb +107 -91
- data/lib/active_record/connection_adapters/postgresql/schema_dumper.rb +0 -1
- data/lib/active_record/connection_adapters/postgresql/schema_statements.rb +63 -75
- data/lib/active_record/connection_adapters/postgresql/type_metadata.rb +24 -27
- data/lib/active_record/connection_adapters/postgresql/utils.rb +0 -1
- data/lib/active_record/connection_adapters/postgresql_adapter.rb +168 -75
- data/lib/active_record/connection_adapters/schema_cache.rb +37 -14
- data/lib/active_record/connection_adapters/sql_type_metadata.rb +11 -8
- data/lib/active_record/connection_adapters/sqlite3/database_statements.rb +119 -0
- data/lib/active_record/connection_adapters/sqlite3/quoting.rb +42 -7
- data/lib/active_record/connection_adapters/sqlite3/schema_statements.rb +43 -12
- data/lib/active_record/connection_adapters/sqlite3_adapter.rb +137 -147
- data/lib/active_record/connection_adapters/statement_pool.rb +0 -1
- data/lib/active_record/connection_handling.rb +139 -26
- data/lib/active_record/core.rb +107 -66
- data/lib/active_record/counter_cache.rb +8 -30
- 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/dynamic_matchers.rb +3 -4
- data/lib/active_record/enum.rb +44 -7
- data/lib/active_record/errors.rb +15 -7
- data/lib/active_record/explain.rb +1 -2
- 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 +144 -474
- data/lib/active_record/gem_version.rb +3 -3
- data/lib/active_record/inheritance.rb +13 -6
- data/lib/active_record/insert_all.rb +179 -0
- data/lib/active_record/integration.rb +68 -16
- data/lib/active_record/internal_metadata.rb +11 -3
- data/lib/active_record/locking/optimistic.rb +14 -7
- data/lib/active_record/locking/pessimistic.rb +3 -3
- data/lib/active_record/log_subscriber.rb +8 -27
- 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 +54 -22
- data/lib/active_record/migration/compatibility.rb +79 -52
- data/lib/active_record/migration/join_table.rb +0 -1
- data/lib/active_record/migration.rb +104 -85
- data/lib/active_record/model_schema.rb +62 -11
- data/lib/active_record/nested_attributes.rb +2 -4
- data/lib/active_record/no_touching.rb +9 -2
- data/lib/active_record/null_relation.rb +0 -1
- data/lib/active_record/persistence.rb +232 -29
- data/lib/active_record/query_cache.rb +11 -4
- data/lib/active_record/querying.rb +33 -21
- data/lib/active_record/railtie.rb +80 -43
- data/lib/active_record/railties/collection_cache_association_loading.rb +34 -0
- data/lib/active_record/railties/controller_runtime.rb +30 -35
- data/lib/active_record/railties/databases.rake +199 -46
- data/lib/active_record/reflection.rb +51 -51
- data/lib/active_record/relation/batches.rb +13 -11
- data/lib/active_record/relation/calculations.rb +55 -49
- data/lib/active_record/relation/delegation.rb +35 -50
- data/lib/active_record/relation/finder_methods.rb +23 -28
- data/lib/active_record/relation/from_clause.rb +4 -0
- data/lib/active_record/relation/merger.rb +12 -17
- data/lib/active_record/relation/predicate_builder/array_handler.rb +5 -4
- data/lib/active_record/relation/predicate_builder/association_query_value.rb +1 -4
- data/lib/active_record/relation/predicate_builder/base_handler.rb +1 -2
- data/lib/active_record/relation/predicate_builder/basic_object_handler.rb +1 -2
- data/lib/active_record/relation/predicate_builder/polymorphic_array_value.rb +1 -4
- data/lib/active_record/relation/predicate_builder/range_handler.rb +3 -23
- data/lib/active_record/relation/predicate_builder.rb +5 -11
- data/lib/active_record/relation/query_attribute.rb +13 -8
- data/lib/active_record/relation/query_methods.rb +232 -69
- data/lib/active_record/relation/spawn_methods.rb +1 -2
- data/lib/active_record/relation/where_clause.rb +14 -11
- data/lib/active_record/relation/where_clause_factory.rb +1 -2
- data/lib/active_record/relation.rb +326 -81
- data/lib/active_record/result.rb +30 -12
- data/lib/active_record/sanitization.rb +32 -40
- data/lib/active_record/schema.rb +2 -11
- data/lib/active_record/schema_dumper.rb +22 -7
- data/lib/active_record/schema_migration.rb +6 -2
- data/lib/active_record/scoping/default.rb +4 -6
- data/lib/active_record/scoping/named.rb +25 -16
- data/lib/active_record/scoping.rb +8 -9
- data/lib/active_record/statement_cache.rb +30 -3
- data/lib/active_record/store.rb +87 -8
- data/lib/active_record/suppressor.rb +2 -2
- data/lib/active_record/table_metadata.rb +23 -15
- data/lib/active_record/tasks/database_tasks.rb +194 -25
- data/lib/active_record/tasks/mysql_database_tasks.rb +5 -6
- data/lib/active_record/tasks/postgresql_database_tasks.rb +5 -8
- data/lib/active_record/tasks/sqlite_database_tasks.rb +2 -9
- data/lib/active_record/test_databases.rb +23 -0
- data/lib/active_record/test_fixtures.rb +243 -0
- data/lib/active_record/timestamp.rb +39 -26
- data/lib/active_record/touch_later.rb +5 -4
- data/lib/active_record/transactions.rb +64 -73
- data/lib/active_record/translation.rb +1 -1
- data/lib/active_record/type/adapter_specific_registry.rb +3 -13
- data/lib/active_record/type/hash_lookup_type_map.rb +0 -1
- data/lib/active_record/type/serialized.rb +0 -1
- data/lib/active_record/type/time.rb +10 -0
- data/lib/active_record/type/type_map.rb +0 -1
- data/lib/active_record/type/unsigned_integer.rb +0 -1
- data/lib/active_record/type.rb +3 -5
- data/lib/active_record/type_caster/connection.rb +15 -14
- data/lib/active_record/type_caster/map.rb +1 -4
- data/lib/active_record/validations/associated.rb +0 -1
- data/lib/active_record/validations/uniqueness.rb +15 -27
- data/lib/active_record/validations.rb +3 -3
- data/lib/active_record.rb +10 -2
- 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 +0 -1
- data/lib/rails/generators/active_record/migration/migration_generator.rb +2 -5
- data/lib/rails/generators/active_record/migration/templates/create_table_migration.rb.tt +1 -1
- data/lib/rails/generators/active_record/migration/templates/migration.rb.tt +4 -2
- data/lib/rails/generators/active_record/migration.rb +14 -2
- data/lib/rails/generators/active_record/model/model_generator.rb +1 -1
- data/lib/rails/generators/active_record/model/templates/model.rb.tt +10 -1
- metadata +116 -29
- data/lib/active_record/collection_cache_key.rb +0 -53
@@ -92,7 +92,7 @@ module ActiveRecord
|
|
92
92
|
through_reflection = reflection.through_reflection
|
93
93
|
source_reflection_names = reflection.source_reflection_names
|
94
94
|
source_associations = reflection.through_reflection.klass._reflections.keys
|
95
|
-
super("Could not find the source association(s) #{source_reflection_names.collect(&:inspect).to_sentence(two_words_connector: ' or ', last_word_connector: ', or '
|
95
|
+
super("Could not find the source association(s) #{source_reflection_names.collect(&:inspect).to_sentence(two_words_connector: ' or ', last_word_connector: ', or ')} in model #{through_reflection.klass}. Try 'has_many #{reflection.name.inspect}, :through => #{through_reflection.name.inspect}, :source => <name>'. Is it one of #{source_associations.to_sentence(two_words_connector: ' or ', last_word_connector: ', or ')}?")
|
96
96
|
else
|
97
97
|
super("Could not find the source association(s).")
|
98
98
|
end
|
@@ -292,13 +292,13 @@ module ActiveRecord
|
|
292
292
|
#
|
293
293
|
# The project class now has the following methods (and more) to ease the traversal and
|
294
294
|
# manipulation of its relationships:
|
295
|
-
# * <tt>Project#portfolio
|
296
|
-
# * <tt>Project#project_manager
|
297
|
-
# * <tt>Project#milestones.empty
|
298
|
-
# <tt>Project#milestones.delete(milestone)
|
299
|
-
# <tt>Project#milestones.build
|
300
|
-
# * <tt>Project#categories.empty
|
301
|
-
# <tt>Project#categories.delete(category1)
|
295
|
+
# * <tt>Project#portfolio</tt>, <tt>Project#portfolio=(portfolio)</tt>, <tt>Project#reload_portfolio</tt>
|
296
|
+
# * <tt>Project#project_manager</tt>, <tt>Project#project_manager=(project_manager)</tt>, <tt>Project#reload_project_manager</tt>
|
297
|
+
# * <tt>Project#milestones.empty?</tt>, <tt>Project#milestones.size</tt>, <tt>Project#milestones</tt>, <tt>Project#milestones<<(milestone)</tt>,
|
298
|
+
# <tt>Project#milestones.delete(milestone)</tt>, <tt>Project#milestones.destroy(milestone)</tt>, <tt>Project#milestones.find(milestone_id)</tt>,
|
299
|
+
# <tt>Project#milestones.build</tt>, <tt>Project#milestones.create</tt>
|
300
|
+
# * <tt>Project#categories.empty?</tt>, <tt>Project#categories.size</tt>, <tt>Project#categories</tt>, <tt>Project#categories<<(category1)</tt>,
|
301
|
+
# <tt>Project#categories.delete(category1)</tt>, <tt>Project#categories.destroy(category1)</tt>
|
302
302
|
#
|
303
303
|
# === A word of warning
|
304
304
|
#
|
@@ -703,8 +703,9 @@ module ActiveRecord
|
|
703
703
|
# #belongs_to associations.
|
704
704
|
#
|
705
705
|
# Extra options on the associations, as defined in the
|
706
|
-
# <tt>AssociationReflection::INVALID_AUTOMATIC_INVERSE_OPTIONS</tt>
|
707
|
-
# also prevent the association's inverse
|
706
|
+
# <tt>AssociationReflection::INVALID_AUTOMATIC_INVERSE_OPTIONS</tt>
|
707
|
+
# constant, or a custom scope, will also prevent the association's inverse
|
708
|
+
# from being found automatically.
|
708
709
|
#
|
709
710
|
# The automatic guessing of the inverse association uses a heuristic based
|
710
711
|
# on the name of the class, so it may not work for all associations,
|
@@ -1293,8 +1294,9 @@ module ActiveRecord
|
|
1293
1294
|
#
|
1294
1295
|
# * <tt>:destroy</tt> causes all the associated objects to also be destroyed.
|
1295
1296
|
# * <tt>:delete_all</tt> causes all the associated objects to be deleted directly from the database (so callbacks will not be executed).
|
1296
|
-
# * <tt>:nullify</tt> causes the foreign keys to be set to +NULL+.
|
1297
|
-
#
|
1297
|
+
# * <tt>:nullify</tt> causes the foreign keys to be set to +NULL+. Polymorphic type will also be nullified
|
1298
|
+
# on polymorphic associations. Callbacks are not executed.
|
1299
|
+
# * <tt>:restrict_with_exception</tt> causes an <tt>ActiveRecord::DeleteRestrictionError</tt> exception to be raised if there are any associated records.
|
1298
1300
|
# * <tt>:restrict_with_error</tt> causes an error to be added to the owner if there are any associated objects.
|
1299
1301
|
#
|
1300
1302
|
# If using with the <tt>:through</tt> option, the association on the join model must be
|
@@ -1436,8 +1438,9 @@ module ActiveRecord
|
|
1436
1438
|
#
|
1437
1439
|
# * <tt>:destroy</tt> causes the associated object to also be destroyed
|
1438
1440
|
# * <tt>:delete</tt> causes the associated object to be deleted directly from the database (so callbacks will not execute)
|
1439
|
-
# * <tt>:nullify</tt> causes the foreign key to be set to +NULL+.
|
1440
|
-
#
|
1441
|
+
# * <tt>:nullify</tt> causes the foreign key to be set to +NULL+. Polymorphic type column is also nullified
|
1442
|
+
# on polymorphic associations. Callbacks are not executed.
|
1443
|
+
# * <tt>:restrict_with_exception</tt> causes an <tt>ActiveRecord::DeleteRestrictionError</tt> exception to be raised if there is an associated record
|
1441
1444
|
# * <tt>:restrict_with_error</tt> causes an error to be added to the owner if there is an associated object
|
1442
1445
|
#
|
1443
1446
|
# Note that <tt>:dependent</tt> option is ignored when using <tt>:through</tt> option.
|
@@ -1524,6 +1527,7 @@ module ActiveRecord
|
|
1524
1527
|
# Returns the associated object. +nil+ is returned if none is found.
|
1525
1528
|
# [association=(associate)]
|
1526
1529
|
# Assigns the associate object, extracts the primary key, and sets it as the foreign key.
|
1530
|
+
# No modification or deletion of existing records takes place.
|
1527
1531
|
# [build_association(attributes = {})]
|
1528
1532
|
# Returns a new object of the associated type that has been instantiated
|
1529
1533
|
# with +attributes+ and linked to this object through a foreign key, but has not yet been saved.
|
@@ -1581,7 +1585,7 @@ module ActiveRecord
|
|
1581
1585
|
# association will use "taggable_type" as the default <tt>:foreign_type</tt>.
|
1582
1586
|
# [:primary_key]
|
1583
1587
|
# Specify the method that returns the primary key of associated object used for the association.
|
1584
|
-
# By default this is id
|
1588
|
+
# By default this is +id+.
|
1585
1589
|
# [:dependent]
|
1586
1590
|
# If set to <tt>:destroy</tt>, the associated object is destroyed when this object is. If set to
|
1587
1591
|
# <tt>:delete</tt>, the associated object is deleted *without* calling its destroy method.
|
@@ -1761,6 +1765,7 @@ module ActiveRecord
|
|
1761
1765
|
# has_and_belongs_to_many :projects, -> { includes(:milestones, :manager) }
|
1762
1766
|
# has_and_belongs_to_many :categories, ->(post) {
|
1763
1767
|
# where("default_category = ?", post.default_category)
|
1768
|
+
# }
|
1764
1769
|
#
|
1765
1770
|
# === Extensions
|
1766
1771
|
#
|
@@ -1852,7 +1857,7 @@ module ActiveRecord
|
|
1852
1857
|
hm_options[k] = options[k] if options.key? k
|
1853
1858
|
end
|
1854
1859
|
|
1855
|
-
has_many name, scope, hm_options, &extension
|
1860
|
+
has_many name, scope, **hm_options, &extension
|
1856
1861
|
_reflections[name.to_s].parent_reflection = habtm_reflection
|
1857
1862
|
end
|
1858
1863
|
end
|
@@ -4,11 +4,9 @@ require "active_model/forbidden_attributes_protection"
|
|
4
4
|
|
5
5
|
module ActiveRecord
|
6
6
|
module AttributeAssignment
|
7
|
-
extend ActiveSupport::Concern
|
8
7
|
include ActiveModel::AttributeAssignment
|
9
8
|
|
10
9
|
private
|
11
|
-
|
12
10
|
def _assign_attributes(attributes)
|
13
11
|
multi_parameter_attributes = {}
|
14
12
|
nested_parameter_attributes = {}
|
@@ -46,16 +44,14 @@ module ActiveRecord
|
|
46
44
|
def execute_callstack_for_multiparameter_attributes(callstack)
|
47
45
|
errors = []
|
48
46
|
callstack.each do |name, values_with_empty_parameters|
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
values = values_with_empty_parameters
|
54
|
-
end
|
55
|
-
send("#{name}=", values)
|
56
|
-
rescue => ex
|
57
|
-
errors << AttributeAssignmentError.new("error on assignment #{values_with_empty_parameters.values.inspect} to #{name} (#{ex.message})", ex, name)
|
47
|
+
if values_with_empty_parameters.each_value.all?(&:nil?)
|
48
|
+
values = nil
|
49
|
+
else
|
50
|
+
values = values_with_empty_parameters
|
58
51
|
end
|
52
|
+
send("#{name}=", values)
|
53
|
+
rescue => ex
|
54
|
+
errors << AttributeAssignmentError.new("error on assignment #{values_with_empty_parameters.values.inspect} to #{name} (#{ex.message})", ex, name)
|
59
55
|
end
|
60
56
|
unless errors.empty?
|
61
57
|
error_descriptions = errors.map(&:message).join(",")
|
@@ -46,7 +46,6 @@ module ActiveRecord
|
|
46
46
|
end
|
47
47
|
|
48
48
|
private
|
49
|
-
|
50
49
|
def load_schema!
|
51
50
|
super
|
52
51
|
attribute_types.each do |name, type|
|
@@ -75,7 +74,6 @@ module ActiveRecord
|
|
75
74
|
end
|
76
75
|
|
77
76
|
private
|
78
|
-
|
79
77
|
def decorators_for(name, type)
|
80
78
|
matching(name, type).map(&:last)
|
81
79
|
end
|
@@ -46,6 +46,7 @@ module ActiveRecord
|
|
46
46
|
# task.read_attribute_before_type_cast('completed_on') # => "2012-10-21"
|
47
47
|
# task.read_attribute_before_type_cast(:completed_on) # => "2012-10-21"
|
48
48
|
def read_attribute_before_type_cast(attr_name)
|
49
|
+
sync_with_transaction_state if @transaction_state&.finalized?
|
49
50
|
@attributes[attr_name.to_s].value_before_type_cast
|
50
51
|
end
|
51
52
|
|
@@ -60,17 +61,18 @@ module ActiveRecord
|
|
60
61
|
# task.attributes_before_type_cast
|
61
62
|
# # => {"id"=>nil, "title"=>nil, "is_done"=>true, "completed_on"=>"2012-10-21", "created_at"=>nil, "updated_at"=>nil}
|
62
63
|
def attributes_before_type_cast
|
64
|
+
sync_with_transaction_state if @transaction_state&.finalized?
|
63
65
|
@attributes.values_before_type_cast
|
64
66
|
end
|
65
67
|
|
66
68
|
private
|
67
|
-
|
68
|
-
# Handle *_before_type_cast for method_missing.
|
69
|
+
# Dispatch target for <tt>*_before_type_cast</tt> attribute methods.
|
69
70
|
def attribute_before_type_cast(attribute_name)
|
70
71
|
read_attribute_before_type_cast(attribute_name)
|
71
72
|
end
|
72
73
|
|
73
74
|
def attribute_came_from_user?(attribute_name)
|
75
|
+
sync_with_transaction_state if @transaction_state&.finalized?
|
74
76
|
@attributes[attribute_name].came_from_user?
|
75
77
|
end
|
76
78
|
end
|
@@ -29,18 +29,17 @@ module ActiveRecord
|
|
29
29
|
# <tt>reload</tt> the record and clears changed attributes.
|
30
30
|
def reload(*)
|
31
31
|
super.tap do
|
32
|
-
@previously_changed = ActiveSupport::HashWithIndifferentAccess.new
|
33
32
|
@mutations_before_last_save = nil
|
34
|
-
@attributes_changed_by_setter = ActiveSupport::HashWithIndifferentAccess.new
|
35
33
|
@mutations_from_database = nil
|
36
34
|
end
|
37
35
|
end
|
38
36
|
|
39
|
-
# Did this attribute change when we last saved?
|
40
|
-
#
|
41
|
-
#
|
42
|
-
#
|
43
|
-
#
|
37
|
+
# Did this attribute change when we last saved?
|
38
|
+
#
|
39
|
+
# This method is useful in after callbacks to determine if an attribute
|
40
|
+
# was changed during the save that triggered the callbacks to run. It can
|
41
|
+
# be invoked as +saved_change_to_name?+ instead of
|
42
|
+
# <tt>saved_change_to_attribute?("name")</tt>.
|
44
43
|
#
|
45
44
|
# ==== Options
|
46
45
|
#
|
@@ -50,28 +49,29 @@ module ActiveRecord
|
|
50
49
|
# +to+ When passed, this method will return false unless the value was
|
51
50
|
# changed to the given value
|
52
51
|
def saved_change_to_attribute?(attr_name, **options)
|
53
|
-
mutations_before_last_save.changed?(attr_name, **options)
|
52
|
+
mutations_before_last_save.changed?(attr_name.to_s, **options)
|
54
53
|
end
|
55
54
|
|
56
55
|
# Returns the change to an attribute during the last save. If the
|
57
56
|
# attribute was changed, the result will be an array containing the
|
58
57
|
# original value and the saved value.
|
59
58
|
#
|
60
|
-
#
|
61
|
-
#
|
62
|
-
#
|
63
|
-
#
|
64
|
-
# <tt>saved_change_to_attribute("name")</tt>
|
59
|
+
# This method is useful in after callbacks, to see the change in an
|
60
|
+
# attribute during the save that triggered the callbacks to run. It can be
|
61
|
+
# invoked as +saved_change_to_name+ instead of
|
62
|
+
# <tt>saved_change_to_attribute("name")</tt>.
|
65
63
|
def saved_change_to_attribute(attr_name)
|
66
|
-
mutations_before_last_save.change_to_attribute(attr_name)
|
64
|
+
mutations_before_last_save.change_to_attribute(attr_name.to_s)
|
67
65
|
end
|
68
66
|
|
69
67
|
# Returns the original value of an attribute before the last save.
|
70
|
-
#
|
71
|
-
# callbacks to get the original value of an
|
72
|
-
#
|
68
|
+
#
|
69
|
+
# This method is useful in after callbacks to get the original value of an
|
70
|
+
# attribute before the save that triggered the callbacks to run. It can be
|
71
|
+
# invoked as +name_before_last_save+ instead of
|
72
|
+
# <tt>attribute_before_last_save("name")</tt>.
|
73
73
|
def attribute_before_last_save(attr_name)
|
74
|
-
mutations_before_last_save.original_value(attr_name)
|
74
|
+
mutations_before_last_save.original_value(attr_name.to_s)
|
75
75
|
end
|
76
76
|
|
77
77
|
# Did the last call to +save+ have any changes to change?
|
@@ -84,66 +84,137 @@ module ActiveRecord
|
|
84
84
|
mutations_before_last_save.changes
|
85
85
|
end
|
86
86
|
|
87
|
-
#
|
87
|
+
# Will this attribute change the next time we save?
|
88
|
+
#
|
89
|
+
# This method is useful in validations and before callbacks to determine
|
90
|
+
# if the next call to +save+ will change a particular attribute. It can be
|
91
|
+
# invoked as +will_save_change_to_name?+ instead of
|
92
|
+
# <tt>will_save_change_to_attribute("name")</tt>.
|
93
|
+
#
|
94
|
+
# ==== Options
|
95
|
+
#
|
96
|
+
# +from+ When passed, this method will return false unless the original
|
97
|
+
# value is equal to the given option
|
98
|
+
#
|
99
|
+
# +to+ When passed, this method will return false unless the value will be
|
100
|
+
# changed to the given value
|
88
101
|
def will_save_change_to_attribute?(attr_name, **options)
|
89
|
-
mutations_from_database.changed?(attr_name, **options)
|
102
|
+
mutations_from_database.changed?(attr_name.to_s, **options)
|
90
103
|
end
|
91
104
|
|
92
|
-
#
|
105
|
+
# Returns the change to an attribute that will be persisted during the
|
106
|
+
# next save.
|
107
|
+
#
|
108
|
+
# This method is useful in validations and before callbacks, to see the
|
109
|
+
# change to an attribute that will occur when the record is saved. It can
|
110
|
+
# be invoked as +name_change_to_be_saved+ instead of
|
111
|
+
# <tt>attribute_change_to_be_saved("name")</tt>.
|
112
|
+
#
|
113
|
+
# If the attribute will change, the result will be an array containing the
|
114
|
+
# original value and the new value about to be saved.
|
93
115
|
def attribute_change_to_be_saved(attr_name)
|
94
|
-
mutations_from_database.change_to_attribute(attr_name)
|
116
|
+
mutations_from_database.change_to_attribute(attr_name.to_s)
|
95
117
|
end
|
96
118
|
|
97
|
-
#
|
119
|
+
# Returns the value of an attribute in the database, as opposed to the
|
120
|
+
# in-memory value that will be persisted the next time the record is
|
121
|
+
# saved.
|
122
|
+
#
|
123
|
+
# This method is useful in validations and before callbacks, to see the
|
124
|
+
# original value of an attribute prior to any changes about to be
|
125
|
+
# saved. It can be invoked as +name_in_database+ instead of
|
126
|
+
# <tt>attribute_in_database("name")</tt>.
|
98
127
|
def attribute_in_database(attr_name)
|
99
|
-
mutations_from_database.original_value(attr_name)
|
128
|
+
mutations_from_database.original_value(attr_name.to_s)
|
100
129
|
end
|
101
130
|
|
102
|
-
#
|
131
|
+
# Will the next call to +save+ have any changes to persist?
|
103
132
|
def has_changes_to_save?
|
104
133
|
mutations_from_database.any_changes?
|
105
134
|
end
|
106
135
|
|
107
|
-
#
|
136
|
+
# Returns a hash containing all the changes that will be persisted during
|
137
|
+
# the next save.
|
108
138
|
def changes_to_save
|
109
139
|
mutations_from_database.changes
|
110
140
|
end
|
111
141
|
|
112
|
-
#
|
142
|
+
# Returns an array of the names of any attributes that will change when
|
143
|
+
# the record is next saved.
|
113
144
|
def changed_attribute_names_to_save
|
114
145
|
mutations_from_database.changed_attribute_names
|
115
146
|
end
|
116
147
|
|
117
|
-
#
|
148
|
+
# Returns a hash of the attributes that will change when the record is
|
149
|
+
# next saved.
|
150
|
+
#
|
151
|
+
# The hash keys are the attribute names, and the hash values are the
|
152
|
+
# original attribute values in the database (as opposed to the in-memory
|
153
|
+
# values about to be saved).
|
118
154
|
def attributes_in_database
|
119
155
|
mutations_from_database.changed_values
|
120
156
|
end
|
121
157
|
|
122
158
|
private
|
159
|
+
def mutations_from_database
|
160
|
+
sync_with_transaction_state if @transaction_state&.finalized?
|
161
|
+
super
|
162
|
+
end
|
163
|
+
|
164
|
+
def mutations_before_last_save
|
165
|
+
sync_with_transaction_state if @transaction_state&.finalized?
|
166
|
+
super
|
167
|
+
end
|
168
|
+
|
123
169
|
def write_attribute_without_type_cast(attr_name, value)
|
124
|
-
|
125
|
-
|
126
|
-
name = self.class.attribute_alias(name)
|
127
|
-
end
|
128
|
-
result = super(name, value)
|
129
|
-
clear_attribute_change(name)
|
170
|
+
result = super
|
171
|
+
clear_attribute_change(attr_name)
|
130
172
|
result
|
131
173
|
end
|
132
174
|
|
133
|
-
def
|
134
|
-
|
175
|
+
def _touch_row(attribute_names, time)
|
176
|
+
@_touch_attr_names = Set.new(attribute_names)
|
177
|
+
|
178
|
+
affected_rows = super
|
179
|
+
|
180
|
+
if @_skip_dirty_tracking ||= false
|
181
|
+
clear_attribute_changes(@_touch_attr_names)
|
182
|
+
return affected_rows
|
183
|
+
end
|
184
|
+
|
185
|
+
changes = {}
|
186
|
+
@attributes.keys.each do |attr_name|
|
187
|
+
next if @_touch_attr_names.include?(attr_name)
|
188
|
+
|
189
|
+
if attribute_changed?(attr_name)
|
190
|
+
changes[attr_name] = _read_attribute(attr_name)
|
191
|
+
_write_attribute(attr_name, attribute_was(attr_name))
|
192
|
+
clear_attribute_change(attr_name)
|
193
|
+
end
|
194
|
+
end
|
195
|
+
|
196
|
+
changes_applied
|
197
|
+
changes.each { |attr_name, value| _write_attribute(attr_name, value) }
|
198
|
+
|
199
|
+
affected_rows
|
200
|
+
ensure
|
201
|
+
@_touch_attr_names, @_skip_dirty_tracking = nil, nil
|
202
|
+
end
|
203
|
+
|
204
|
+
def _update_record(attribute_names = attribute_names_for_partial_writes)
|
205
|
+
affected_rows = super
|
135
206
|
changes_applied
|
136
207
|
affected_rows
|
137
208
|
end
|
138
209
|
|
139
|
-
def _create_record(
|
140
|
-
id =
|
210
|
+
def _create_record(attribute_names = attribute_names_for_partial_writes)
|
211
|
+
id = super
|
141
212
|
changes_applied
|
142
213
|
id
|
143
214
|
end
|
144
215
|
|
145
|
-
def
|
146
|
-
changed_attribute_names_to_save
|
216
|
+
def attribute_names_for_partial_writes
|
217
|
+
partial_writes? ? changed_attribute_names_to_save : attribute_names
|
147
218
|
end
|
148
219
|
end
|
149
220
|
end
|
@@ -14,45 +14,37 @@ module ActiveRecord
|
|
14
14
|
[key] if key
|
15
15
|
end
|
16
16
|
|
17
|
-
# Returns the primary key value.
|
17
|
+
# Returns the primary key column's value.
|
18
18
|
def id
|
19
|
-
|
20
|
-
primary_key = self.class.primary_key
|
21
|
-
_read_attribute(primary_key) if primary_key
|
19
|
+
_read_attribute(@primary_key)
|
22
20
|
end
|
23
21
|
|
24
|
-
# Sets the primary key value.
|
22
|
+
# Sets the primary key column's value.
|
25
23
|
def id=(value)
|
26
|
-
|
27
|
-
primary_key = self.class.primary_key
|
28
|
-
_write_attribute(primary_key, value) if primary_key
|
24
|
+
_write_attribute(@primary_key, value)
|
29
25
|
end
|
30
26
|
|
31
|
-
# Queries the primary key value.
|
27
|
+
# Queries the primary key column's value.
|
32
28
|
def id?
|
33
|
-
|
34
|
-
query_attribute(self.class.primary_key)
|
29
|
+
query_attribute(@primary_key)
|
35
30
|
end
|
36
31
|
|
37
|
-
# Returns the primary key value before type cast.
|
32
|
+
# Returns the primary key column's value before type cast.
|
38
33
|
def id_before_type_cast
|
39
|
-
|
40
|
-
read_attribute_before_type_cast(self.class.primary_key)
|
34
|
+
read_attribute_before_type_cast(@primary_key)
|
41
35
|
end
|
42
36
|
|
43
|
-
# Returns the primary key previous value.
|
37
|
+
# Returns the primary key column's previous value.
|
44
38
|
def id_was
|
45
|
-
|
46
|
-
attribute_was(self.class.primary_key)
|
39
|
+
attribute_was(@primary_key)
|
47
40
|
end
|
48
41
|
|
42
|
+
# Returns the primary key column's value from the database.
|
49
43
|
def id_in_database
|
50
|
-
|
51
|
-
attribute_in_database(self.class.primary_key)
|
44
|
+
attribute_in_database(@primary_key)
|
52
45
|
end
|
53
46
|
|
54
47
|
private
|
55
|
-
|
56
48
|
def attribute_method?(attr_name)
|
57
49
|
attr_name == "id" || super
|
58
50
|
end
|
@@ -83,7 +75,7 @@ module ActiveRecord
|
|
83
75
|
end
|
84
76
|
|
85
77
|
def reset_primary_key #:nodoc:
|
86
|
-
if
|
78
|
+
if base_class?
|
87
79
|
self.primary_key = get_primary_key(base_class.name)
|
88
80
|
else
|
89
81
|
self.primary_key = base_class.primary_key
|
@@ -121,17 +113,16 @@ module ActiveRecord
|
|
121
113
|
#
|
122
114
|
# Project.primary_key # => "foo_id"
|
123
115
|
def primary_key=(value)
|
124
|
-
@primary_key = value && value.to_s
|
116
|
+
@primary_key = value && -value.to_s
|
125
117
|
@quoted_primary_key = nil
|
126
118
|
@attributes_builder = nil
|
127
119
|
end
|
128
120
|
|
129
121
|
private
|
130
|
-
|
131
122
|
def suppress_composite_primary_key(pk)
|
132
123
|
return pk unless pk.is_a?(Array)
|
133
124
|
|
134
|
-
warn
|
125
|
+
warn <<~WARNING
|
135
126
|
WARNING: Active Record does not support composite primary key.
|
136
127
|
|
137
128
|
#{table_name} has composite primary key. Composite primary key is ignored.
|
@@ -16,8 +16,7 @@ module ActiveRecord
|
|
16
16
|
when true then true
|
17
17
|
when false, nil then false
|
18
18
|
else
|
19
|
-
|
20
|
-
if column.nil?
|
19
|
+
if !type_for_attribute(attr_name) { false }
|
21
20
|
if Numeric === value || value !~ /[^0-9]/
|
22
21
|
!value.to_i.zero?
|
23
22
|
else
|
@@ -33,7 +32,7 @@ module ActiveRecord
|
|
33
32
|
end
|
34
33
|
|
35
34
|
private
|
36
|
-
#
|
35
|
+
# Dispatch target for <tt>*?</tt> attribute methods.
|
37
36
|
def attribute?(attribute_name)
|
38
37
|
query_attribute(attribute_name)
|
39
38
|
end
|
@@ -7,43 +7,16 @@ module ActiveRecord
|
|
7
7
|
|
8
8
|
module ClassMethods # :nodoc:
|
9
9
|
private
|
10
|
-
|
11
|
-
# We want to generate the methods via module_eval rather than
|
12
|
-
# define_method, because define_method is slower on dispatch.
|
13
|
-
# Evaluating many similar methods may use more memory as the instruction
|
14
|
-
# sequences are duplicated and cached (in MRI). define_method may
|
15
|
-
# be slower on dispatch, but if you're careful about the closure
|
16
|
-
# created, then define_method will consume much less memory.
|
17
|
-
#
|
18
|
-
# But sometimes the database might return columns with
|
19
|
-
# characters that are not allowed in normal method names (like
|
20
|
-
# 'my_column(omg)'. So to work around this we first define with
|
21
|
-
# the __temp__ identifier, and then use alias method to rename
|
22
|
-
# it to what we want.
|
23
|
-
#
|
24
|
-
# We are also defining a constant to hold the frozen string of
|
25
|
-
# the attribute name. Using a constant means that we do not have
|
26
|
-
# to allocate an object on each call to the attribute method.
|
27
|
-
# Making it frozen means that it doesn't get duped when used to
|
28
|
-
# key the @attributes in read_attribute.
|
29
10
|
def define_method_attribute(name)
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
name = ::ActiveRecord::AttributeMethods::AttrNames::ATTR_#{safe_name}
|
40
|
-
_read_attribute(name) { |n| missing_attribute(n, caller) }
|
41
|
-
end
|
42
|
-
STR
|
43
|
-
|
44
|
-
generated_attribute_methods.module_eval do
|
45
|
-
alias_method name, temp_method
|
46
|
-
undef_method temp_method
|
11
|
+
ActiveModel::AttributeMethods::AttrNames.define_attribute_accessor_method(
|
12
|
+
generated_attribute_methods, name
|
13
|
+
) do |temp_method_name, attr_name_expr|
|
14
|
+
generated_attribute_methods.module_eval <<-RUBY, __FILE__, __LINE__ + 1
|
15
|
+
def #{temp_method_name}
|
16
|
+
name = #{attr_name_expr}
|
17
|
+
_read_attribute(name) { |n| missing_attribute(n, caller) }
|
18
|
+
end
|
19
|
+
RUBY
|
47
20
|
end
|
48
21
|
end
|
49
22
|
end
|
@@ -52,30 +25,18 @@ module ActiveRecord
|
|
52
25
|
# it has been typecast (for example, "2004-12-12" in a date column is cast
|
53
26
|
# to a date object, like Date.new(2004, 12, 12)).
|
54
27
|
def read_attribute(attr_name, &block)
|
55
|
-
name =
|
56
|
-
|
57
|
-
else
|
58
|
-
attr_name.to_s
|
59
|
-
end
|
28
|
+
name = attr_name.to_s
|
29
|
+
name = self.class.attribute_aliases[name] || name
|
60
30
|
|
61
|
-
|
62
|
-
name = primary_key if name == "id".freeze && primary_key
|
63
|
-
sync_with_transaction_state if name == primary_key
|
31
|
+
name = @primary_key if name == "id" && @primary_key
|
64
32
|
_read_attribute(name, &block)
|
65
33
|
end
|
66
34
|
|
67
35
|
# This method exists to avoid the expensive primary_key check internally, without
|
68
36
|
# breaking compatibility with the read_attribute API
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
def _read_attribute(attr_name, &block) # :nodoc:
|
73
|
-
@attributes.fetch_value(attr_name.to_s, &block)
|
74
|
-
end
|
75
|
-
else
|
76
|
-
def _read_attribute(attr_name) # :nodoc:
|
77
|
-
@attributes.fetch_value(attr_name.to_s) { |n| yield n if block_given? }
|
78
|
-
end
|
37
|
+
def _read_attribute(attr_name, &block) # :nodoc
|
38
|
+
sync_with_transaction_state if @transaction_state&.finalized?
|
39
|
+
@attributes.fetch_value(attr_name.to_s, &block)
|
79
40
|
end
|
80
41
|
|
81
42
|
alias :attribute :_read_attribute
|
@@ -7,7 +7,7 @@ module ActiveRecord
|
|
7
7
|
|
8
8
|
class ColumnNotSerializableError < StandardError
|
9
9
|
def initialize(name, type)
|
10
|
-
super
|
10
|
+
super <<~EOS
|
11
11
|
Column `#{name}` of type #{type.class} does not support `serialize` feature.
|
12
12
|
Usually it means that you are trying to use `serialize`
|
13
13
|
on a column that already implements serialization natively.
|
@@ -79,7 +79,6 @@ module ActiveRecord
|
|
79
79
|
end
|
80
80
|
|
81
81
|
private
|
82
|
-
|
83
82
|
def type_incompatible_with_serialize?(type, class_name)
|
84
83
|
type.is_a?(ActiveRecord::Type::Json) && class_name == ::JSON ||
|
85
84
|
type.respond_to?(:type_cast_array, true) && class_name == ::Array
|
@@ -25,7 +25,6 @@ module ActiveRecord
|
|
25
25
|
end
|
26
26
|
|
27
27
|
private
|
28
|
-
|
29
28
|
def convert_time_to_time_zone(value)
|
30
29
|
return if value.nil?
|
31
30
|
|
@@ -64,7 +63,6 @@ module ActiveRecord
|
|
64
63
|
|
65
64
|
module ClassMethods # :nodoc:
|
66
65
|
private
|
67
|
-
|
68
66
|
def inherited(subclass)
|
69
67
|
super
|
70
68
|
# We need to apply this decorator here, rather than on module inclusion. The closure
|
@@ -73,7 +71,7 @@ module ActiveRecord
|
|
73
71
|
# `skip_time_zone_conversion_for_attributes` would not be picked up.
|
74
72
|
subclass.class_eval do
|
75
73
|
matcher = ->(name, type) { create_time_zone_conversion_attribute?(name, type) }
|
76
|
-
decorate_matching_attribute_types(matcher,
|
74
|
+
decorate_matching_attribute_types(matcher, "_time_zone_conversion") do |type|
|
77
75
|
TimeZoneConverter.new(type)
|
78
76
|
end
|
79
77
|
end
|