activerecord 5.0.6 → 6.0.1
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of activerecord might be problematic. Click here for more details.
- checksums.yaml +5 -5
- data/CHANGELOG.md +638 -2023
- data/MIT-LICENSE +3 -1
- data/README.rdoc +8 -6
- data/examples/performance.rb +31 -29
- data/examples/simple.rb +5 -3
- data/lib/active_record/aggregations.rb +249 -246
- data/lib/active_record/association_relation.rb +24 -13
- data/lib/active_record/associations/alias_tracker.rb +24 -33
- data/lib/active_record/associations/association.rb +119 -56
- data/lib/active_record/associations/association_scope.rb +94 -94
- data/lib/active_record/associations/belongs_to_association.rb +58 -42
- data/lib/active_record/associations/belongs_to_polymorphic_association.rb +8 -12
- data/lib/active_record/associations/builder/association.rb +18 -25
- data/lib/active_record/associations/builder/belongs_to.rb +43 -54
- data/lib/active_record/associations/builder/collection_association.rb +7 -18
- data/lib/active_record/associations/builder/has_and_belongs_to_many.rb +42 -61
- data/lib/active_record/associations/builder/has_many.rb +4 -0
- data/lib/active_record/associations/builder/has_one.rb +37 -1
- data/lib/active_record/associations/builder/singular_association.rb +4 -0
- data/lib/active_record/associations/collection_association.rb +80 -252
- data/lib/active_record/associations/collection_proxy.rb +158 -121
- data/lib/active_record/associations/foreign_association.rb +9 -0
- data/lib/active_record/associations/has_many_association.rb +23 -29
- data/lib/active_record/associations/has_many_through_association.rb +58 -44
- data/lib/active_record/associations/has_one_association.rb +59 -54
- data/lib/active_record/associations/has_one_through_association.rb +20 -11
- data/lib/active_record/associations/join_dependency/join_association.rb +38 -90
- data/lib/active_record/associations/join_dependency/join_base.rb +10 -9
- data/lib/active_record/associations/join_dependency/join_part.rb +12 -12
- data/lib/active_record/associations/join_dependency.rb +134 -176
- data/lib/active_record/associations/preloader/association.rb +84 -125
- data/lib/active_record/associations/preloader/through_association.rb +82 -75
- data/lib/active_record/associations/preloader.rb +90 -102
- data/lib/active_record/associations/singular_association.rb +12 -45
- data/lib/active_record/associations/through_association.rb +26 -14
- data/lib/active_record/associations.rb +1603 -1592
- data/lib/active_record/attribute_assignment.rb +54 -60
- data/lib/active_record/attribute_decorators.rb +38 -15
- data/lib/active_record/attribute_methods/before_type_cast.rb +12 -7
- data/lib/active_record/attribute_methods/dirty.rb +179 -109
- data/lib/active_record/attribute_methods/primary_key.rb +86 -91
- data/lib/active_record/attribute_methods/query.rb +4 -3
- data/lib/active_record/attribute_methods/read.rb +21 -49
- data/lib/active_record/attribute_methods/serialization.rb +30 -7
- data/lib/active_record/attribute_methods/time_zone_conversion.rb +39 -64
- data/lib/active_record/attribute_methods/write.rb +35 -33
- data/lib/active_record/attribute_methods.rb +66 -106
- data/lib/active_record/attributes.rb +38 -24
- data/lib/active_record/autosave_association.rb +53 -32
- data/lib/active_record/base.rb +27 -24
- data/lib/active_record/callbacks.rb +63 -33
- data/lib/active_record/coders/json.rb +2 -0
- data/lib/active_record/coders/yaml_column.rb +11 -11
- data/lib/active_record/connection_adapters/abstract/connection_pool.rb +553 -321
- data/lib/active_record/connection_adapters/abstract/database_limits.rb +23 -5
- data/lib/active_record/connection_adapters/abstract/database_statements.rb +213 -94
- data/lib/active_record/connection_adapters/abstract/query_cache.rb +59 -28
- data/lib/active_record/connection_adapters/abstract/quoting.rb +119 -75
- data/lib/active_record/connection_adapters/abstract/savepoints.rb +2 -0
- data/lib/active_record/connection_adapters/abstract/schema_creation.rb +33 -27
- data/lib/active_record/connection_adapters/abstract/schema_definitions.rb +207 -126
- data/lib/active_record/connection_adapters/abstract/schema_dumper.rb +68 -80
- data/lib/active_record/connection_adapters/abstract/schema_statements.rb +369 -199
- data/lib/active_record/connection_adapters/abstract/transaction.rb +169 -78
- data/lib/active_record/connection_adapters/abstract_adapter.rb +363 -202
- data/lib/active_record/connection_adapters/abstract_mysql_adapter.rb +405 -551
- data/lib/active_record/connection_adapters/column.rb +41 -13
- data/lib/active_record/connection_adapters/connection_specification.rb +172 -138
- data/lib/active_record/connection_adapters/determine_if_preparable_visitor.rb +11 -4
- data/lib/active_record/connection_adapters/mysql/column.rb +8 -31
- data/lib/active_record/connection_adapters/mysql/database_statements.rb +143 -49
- data/lib/active_record/connection_adapters/mysql/explain_pretty_printer.rb +24 -22
- data/lib/active_record/connection_adapters/mysql/quoting.rb +50 -20
- data/lib/active_record/connection_adapters/mysql/schema_creation.rb +50 -45
- data/lib/active_record/connection_adapters/mysql/schema_definitions.rb +58 -56
- data/lib/active_record/connection_adapters/mysql/schema_dumper.rb +70 -36
- data/lib/active_record/connection_adapters/mysql/schema_statements.rb +264 -0
- data/lib/active_record/connection_adapters/mysql/type_metadata.rb +12 -13
- data/lib/active_record/connection_adapters/mysql2_adapter.rb +49 -30
- data/lib/active_record/connection_adapters/postgresql/column.rb +22 -7
- data/lib/active_record/connection_adapters/postgresql/database_statements.rb +60 -54
- data/lib/active_record/connection_adapters/postgresql/explain_pretty_printer.rb +5 -3
- data/lib/active_record/connection_adapters/postgresql/oid/array.rb +22 -10
- data/lib/active_record/connection_adapters/postgresql/oid/bit.rb +6 -5
- data/lib/active_record/connection_adapters/postgresql/oid/bit_varying.rb +2 -0
- data/lib/active_record/connection_adapters/postgresql/oid/bytea.rb +2 -0
- data/lib/active_record/connection_adapters/postgresql/oid/cidr.rb +3 -1
- data/lib/active_record/connection_adapters/postgresql/oid/date.rb +23 -0
- data/lib/active_record/connection_adapters/postgresql/oid/date_time.rb +4 -2
- data/lib/active_record/connection_adapters/postgresql/oid/decimal.rb +3 -1
- data/lib/active_record/connection_adapters/postgresql/oid/enum.rb +5 -3
- data/lib/active_record/connection_adapters/postgresql/oid/hstore.rb +19 -17
- data/lib/active_record/connection_adapters/postgresql/oid/inet.rb +2 -0
- data/lib/active_record/connection_adapters/postgresql/oid/jsonb.rb +3 -11
- data/lib/active_record/connection_adapters/postgresql/oid/legacy_point.rb +45 -0
- data/lib/active_record/connection_adapters/postgresql/oid/money.rb +7 -5
- data/lib/active_record/connection_adapters/postgresql/oid/{json.rb → oid.rb} +6 -1
- data/lib/active_record/connection_adapters/postgresql/oid/point.rb +31 -9
- data/lib/active_record/connection_adapters/postgresql/oid/range.rb +34 -30
- data/lib/active_record/connection_adapters/postgresql/oid/specialized_string.rb +4 -1
- data/lib/active_record/connection_adapters/postgresql/oid/type_map_initializer.rb +58 -54
- data/lib/active_record/connection_adapters/postgresql/oid/uuid.rb +9 -4
- data/lib/active_record/connection_adapters/postgresql/oid/vector.rb +2 -0
- data/lib/active_record/connection_adapters/postgresql/oid/xml.rb +2 -0
- data/lib/active_record/connection_adapters/postgresql/oid.rb +24 -21
- data/lib/active_record/connection_adapters/postgresql/quoting.rb +95 -35
- data/lib/active_record/connection_adapters/postgresql/referential_integrity.rb +19 -25
- data/lib/active_record/connection_adapters/postgresql/schema_creation.rb +76 -0
- data/lib/active_record/connection_adapters/postgresql/schema_definitions.rb +147 -105
- data/lib/active_record/connection_adapters/postgresql/schema_dumper.rb +35 -32
- data/lib/active_record/connection_adapters/postgresql/schema_statements.rb +380 -300
- data/lib/active_record/connection_adapters/postgresql/type_metadata.rb +26 -25
- data/lib/active_record/connection_adapters/postgresql/utils.rb +10 -6
- data/lib/active_record/connection_adapters/postgresql_adapter.rb +382 -275
- data/lib/active_record/connection_adapters/schema_cache.rb +46 -12
- data/lib/active_record/connection_adapters/sql_type_metadata.rb +13 -8
- data/lib/active_record/connection_adapters/sqlite3/database_statements.rb +120 -0
- data/lib/active_record/connection_adapters/sqlite3/explain_pretty_printer.rb +3 -1
- data/lib/active_record/connection_adapters/sqlite3/quoting.rb +74 -19
- data/lib/active_record/connection_adapters/sqlite3/schema_creation.rb +3 -8
- 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 +254 -262
- data/lib/active_record/connection_adapters/statement_pool.rb +9 -7
- data/lib/active_record/connection_handling.rb +159 -40
- data/lib/active_record/core.rb +202 -162
- data/lib/active_record/counter_cache.rb +57 -28
- data/lib/active_record/database_configurations/database_config.rb +37 -0
- data/lib/active_record/database_configurations/hash_config.rb +50 -0
- data/lib/active_record/database_configurations/url_config.rb +79 -0
- data/lib/active_record/database_configurations.rb +233 -0
- data/lib/active_record/define_callbacks.rb +22 -0
- data/lib/active_record/dynamic_matchers.rb +87 -86
- data/lib/active_record/enum.rb +60 -23
- data/lib/active_record/errors.rb +114 -18
- data/lib/active_record/explain.rb +4 -3
- data/lib/active_record/explain_registry.rb +3 -1
- data/lib/active_record/explain_subscriber.rb +9 -4
- data/lib/active_record/fixture_set/file.rb +13 -8
- data/lib/active_record/fixture_set/model_metadata.rb +33 -0
- data/lib/active_record/fixture_set/render_context.rb +17 -0
- data/lib/active_record/fixture_set/table_row.rb +153 -0
- data/lib/active_record/fixture_set/table_rows.rb +47 -0
- data/lib/active_record/fixtures.rb +195 -502
- data/lib/active_record/gem_version.rb +4 -2
- data/lib/active_record/inheritance.rb +151 -97
- data/lib/active_record/insert_all.rb +179 -0
- data/lib/active_record/integration.rb +116 -25
- data/lib/active_record/internal_metadata.rb +15 -18
- data/lib/active_record/legacy_yaml_adapter.rb +4 -2
- data/lib/active_record/locking/optimistic.rb +78 -87
- data/lib/active_record/locking/pessimistic.rb +18 -6
- data/lib/active_record/log_subscriber.rb +48 -29
- data/lib/active_record/middleware/database_selector/resolver/session.rb +45 -0
- data/lib/active_record/middleware/database_selector/resolver.rb +88 -0
- data/lib/active_record/middleware/database_selector.rb +75 -0
- data/lib/active_record/migration/command_recorder.rb +143 -97
- data/lib/active_record/migration/compatibility.rb +174 -56
- data/lib/active_record/migration/join_table.rb +8 -6
- data/lib/active_record/migration.rb +367 -300
- data/lib/active_record/model_schema.rb +145 -139
- data/lib/active_record/nested_attributes.rb +214 -201
- data/lib/active_record/no_touching.rb +10 -1
- data/lib/active_record/null_relation.rb +13 -34
- data/lib/active_record/persistence.rb +442 -72
- data/lib/active_record/query_cache.rb +15 -14
- data/lib/active_record/querying.rb +36 -23
- data/lib/active_record/railtie.rb +128 -36
- 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 +309 -177
- data/lib/active_record/readonly_attributes.rb +5 -4
- data/lib/active_record/reflection.rb +211 -249
- data/lib/active_record/relation/batches/batch_enumerator.rb +3 -1
- data/lib/active_record/relation/batches.rb +99 -52
- data/lib/active_record/relation/calculations.rb +211 -172
- data/lib/active_record/relation/delegation.rb +67 -65
- data/lib/active_record/relation/finder_methods.rb +208 -247
- data/lib/active_record/relation/from_clause.rb +2 -8
- data/lib/active_record/relation/merger.rb +78 -61
- data/lib/active_record/relation/predicate_builder/array_handler.rb +20 -14
- data/lib/active_record/relation/predicate_builder/association_query_value.rb +43 -0
- data/lib/active_record/relation/predicate_builder/base_handler.rb +4 -3
- data/lib/active_record/relation/predicate_builder/basic_object_handler.rb +6 -4
- data/lib/active_record/relation/predicate_builder/polymorphic_array_value.rb +53 -0
- data/lib/active_record/relation/predicate_builder/range_handler.rb +7 -18
- data/lib/active_record/relation/predicate_builder/relation_handler.rb +6 -0
- data/lib/active_record/relation/predicate_builder.rb +86 -104
- data/lib/active_record/relation/query_attribute.rb +33 -2
- data/lib/active_record/relation/query_methods.rb +458 -329
- data/lib/active_record/relation/record_fetch_warning.rb +5 -3
- data/lib/active_record/relation/spawn_methods.rb +8 -7
- data/lib/active_record/relation/where_clause.rb +111 -95
- data/lib/active_record/relation/where_clause_factory.rb +6 -11
- data/lib/active_record/relation.rb +429 -318
- data/lib/active_record/result.rb +69 -39
- data/lib/active_record/runtime_registry.rb +5 -3
- data/lib/active_record/sanitization.rb +83 -99
- data/lib/active_record/schema.rb +7 -14
- data/lib/active_record/schema_dumper.rb +71 -69
- data/lib/active_record/schema_migration.rb +15 -5
- data/lib/active_record/scoping/default.rb +93 -95
- data/lib/active_record/scoping/named.rb +45 -25
- data/lib/active_record/scoping.rb +20 -19
- data/lib/active_record/secure_token.rb +4 -2
- data/lib/active_record/serialization.rb +2 -0
- data/lib/active_record/statement_cache.rb +63 -28
- data/lib/active_record/store.rb +121 -41
- data/lib/active_record/suppressor.rb +4 -1
- data/lib/active_record/table_metadata.rb +26 -20
- data/lib/active_record/tasks/database_tasks.rb +276 -85
- data/lib/active_record/tasks/mysql_database_tasks.rb +54 -90
- data/lib/active_record/tasks/postgresql_database_tasks.rb +78 -47
- data/lib/active_record/tasks/sqlite_database_tasks.rb +34 -16
- data/lib/active_record/test_databases.rb +23 -0
- data/lib/active_record/test_fixtures.rb +224 -0
- data/lib/active_record/timestamp.rb +70 -35
- data/lib/active_record/touch_later.rb +7 -4
- data/lib/active_record/transactions.rb +133 -149
- data/lib/active_record/translation.rb +3 -1
- data/lib/active_record/type/adapter_specific_registry.rb +44 -45
- data/lib/active_record/type/date.rb +2 -0
- data/lib/active_record/type/date_time.rb +2 -0
- data/lib/active_record/type/decimal_without_scale.rb +15 -0
- data/lib/active_record/type/hash_lookup_type_map.rb +5 -3
- data/lib/active_record/type/internal/timezone.rb +2 -0
- data/lib/active_record/type/json.rb +30 -0
- data/lib/active_record/type/serialized.rb +16 -8
- data/lib/active_record/type/text.rb +11 -0
- data/lib/active_record/type/time.rb +2 -1
- data/lib/active_record/type/type_map.rb +13 -15
- data/lib/active_record/type/unsigned_integer.rb +17 -0
- data/lib/active_record/type.rb +23 -17
- data/lib/active_record/type_caster/connection.rb +17 -12
- data/lib/active_record/type_caster/map.rb +5 -4
- data/lib/active_record/type_caster.rb +4 -2
- data/lib/active_record/validations/absence.rb +2 -0
- data/lib/active_record/validations/associated.rb +3 -1
- data/lib/active_record/validations/length.rb +2 -0
- data/lib/active_record/validations/presence.rb +4 -2
- data/lib/active_record/validations/uniqueness.rb +29 -42
- data/lib/active_record/validations.rb +7 -4
- data/lib/active_record/version.rb +3 -1
- data/lib/active_record.rb +36 -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 +257 -0
- data/lib/arel/select_manager.rb +271 -0
- data/lib/arel/table.rb +110 -0
- data/lib/arel/tree_manager.rb +72 -0
- data/lib/arel/update_manager.rb +34 -0
- data/lib/arel/visitors/depth_first.rb +204 -0
- data/lib/arel/visitors/dot.rb +297 -0
- data/lib/arel/visitors/ibm_db.rb +34 -0
- data/lib/arel/visitors/informix.rb +62 -0
- data/lib/arel/visitors/mssql.rb +157 -0
- data/lib/arel/visitors/mysql.rb +83 -0
- data/lib/arel/visitors/oracle.rb +159 -0
- data/lib/arel/visitors/oracle12.rb +66 -0
- data/lib/arel/visitors/postgresql.rb +110 -0
- data/lib/arel/visitors/sqlite.rb +39 -0
- data/lib/arel/visitors/to_sql.rb +889 -0
- data/lib/arel/visitors/visitor.rb +46 -0
- data/lib/arel/visitors/where_sql.rb +23 -0
- data/lib/arel/visitors.rb +20 -0
- data/lib/arel/window_predications.rb +9 -0
- data/lib/arel.rb +58 -0
- data/lib/rails/generators/active_record/application_record/application_record_generator.rb +27 -0
- data/lib/rails/generators/active_record/{model/templates/application_record.rb → application_record/templates/application_record.rb.tt} +0 -0
- data/lib/rails/generators/active_record/migration/migration_generator.rb +37 -35
- data/lib/rails/generators/active_record/migration/templates/{create_table_migration.rb → create_table_migration.rb.tt} +1 -1
- data/lib/rails/generators/active_record/migration/templates/{migration.rb → migration.rb.tt} +4 -2
- data/lib/rails/generators/active_record/migration.rb +17 -2
- data/lib/rails/generators/active_record/model/model_generator.rb +9 -29
- data/lib/rails/generators/active_record/model/templates/{model.rb → model.rb.tt} +10 -1
- 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 +133 -50
- data/lib/active_record/associations/preloader/belongs_to.rb +0 -17
- data/lib/active_record/associations/preloader/collection_association.rb +0 -17
- 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 -15
- data/lib/active_record/associations/preloader/has_one_through.rb +0 -9
- data/lib/active_record/associations/preloader/singular_association.rb +0 -20
- data/lib/active_record/attribute/user_provided_default.rb +0 -28
- data/lib/active_record/attribute.rb +0 -213
- data/lib/active_record/attribute_mutation_tracker.rb +0 -70
- data/lib/active_record/attribute_set/builder.rb +0 -130
- data/lib/active_record/attribute_set.rb +0 -110
- data/lib/active_record/collection_cache_key.rb +0 -50
- data/lib/active_record/connection_adapters/postgresql/oid/rails_5_1_point.rb +0 -50
- data/lib/active_record/railties/jdbcmysql_error.rb +0 -16
- data/lib/active_record/relation/predicate_builder/association_query_handler.rb +0 -88
- data/lib/active_record/relation/predicate_builder/class_handler.rb +0 -27
- data/lib/active_record/relation/predicate_builder/polymorphic_array_handler.rb +0 -57
- data/lib/active_record/type/internal/abstract_json.rb +0 -33
@@ -1,4 +1,6 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "concurrent/map"
|
2
4
|
|
3
5
|
module ActiveRecord
|
4
6
|
module Type
|
@@ -11,7 +13,7 @@ module ActiveRecord
|
|
11
13
|
end
|
12
14
|
|
13
15
|
def lookup(lookup_key, *args)
|
14
|
-
fetch(lookup_key, *args) { default_value }
|
16
|
+
fetch(lookup_key, *args) { Type.default_value }
|
15
17
|
end
|
16
18
|
|
17
19
|
def fetch(lookup_key, *args, &block)
|
@@ -44,21 +46,17 @@ module ActiveRecord
|
|
44
46
|
|
45
47
|
private
|
46
48
|
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
49
|
+
def perform_fetch(lookup_key, *args)
|
50
|
+
matching_pair = @mapping.reverse_each.detect do |key, _|
|
51
|
+
key === lookup_key
|
52
|
+
end
|
51
53
|
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
54
|
+
if matching_pair
|
55
|
+
matching_pair.last.call(lookup_key, *args)
|
56
|
+
else
|
57
|
+
yield lookup_key, *args
|
58
|
+
end
|
56
59
|
end
|
57
|
-
end
|
58
|
-
|
59
|
-
def default_value
|
60
|
-
@default_value ||= ActiveModel::Type::Value.new
|
61
|
-
end
|
62
60
|
end
|
63
61
|
end
|
64
62
|
end
|
data/lib/active_record/type.rb
CHANGED
@@ -1,17 +1,22 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
4
|
-
require 'active_record/type/internal/timezone'
|
3
|
+
require "active_model/type"
|
5
4
|
|
6
|
-
require
|
7
|
-
require 'active_record/type/date_time'
|
8
|
-
require 'active_record/type/time'
|
5
|
+
require "active_record/type/internal/timezone"
|
9
6
|
|
10
|
-
require
|
11
|
-
require
|
7
|
+
require "active_record/type/date"
|
8
|
+
require "active_record/type/date_time"
|
9
|
+
require "active_record/type/decimal_without_scale"
|
10
|
+
require "active_record/type/json"
|
11
|
+
require "active_record/type/time"
|
12
|
+
require "active_record/type/text"
|
13
|
+
require "active_record/type/unsigned_integer"
|
12
14
|
|
13
|
-
require
|
14
|
-
require
|
15
|
+
require "active_record/type/serialized"
|
16
|
+
require "active_record/type/adapter_specific_registry"
|
17
|
+
|
18
|
+
require "active_record/type/type_map"
|
19
|
+
require "active_record/type/hash_lookup_type_map"
|
15
20
|
|
16
21
|
module ActiveRecord
|
17
22
|
module Type
|
@@ -37,24 +42,24 @@ module ActiveRecord
|
|
37
42
|
registry.lookup(*args, adapter: adapter, **kwargs)
|
38
43
|
end
|
39
44
|
|
45
|
+
def default_value # :nodoc:
|
46
|
+
@default_value ||= Value.new
|
47
|
+
end
|
48
|
+
|
40
49
|
private
|
41
50
|
|
42
|
-
|
43
|
-
|
44
|
-
|
51
|
+
def current_adapter_name
|
52
|
+
ActiveRecord::Base.connection.adapter_name.downcase.to_sym
|
53
|
+
end
|
45
54
|
end
|
46
55
|
|
47
|
-
Helpers = ActiveModel::Type::Helpers
|
48
56
|
BigInteger = ActiveModel::Type::BigInteger
|
49
57
|
Binary = ActiveModel::Type::Binary
|
50
58
|
Boolean = ActiveModel::Type::Boolean
|
51
59
|
Decimal = ActiveModel::Type::Decimal
|
52
|
-
DecimalWithoutScale = ActiveModel::Type::DecimalWithoutScale
|
53
60
|
Float = ActiveModel::Type::Float
|
54
61
|
Integer = ActiveModel::Type::Integer
|
55
62
|
String = ActiveModel::Type::String
|
56
|
-
Text = ActiveModel::Type::Text
|
57
|
-
UnsignedInteger = ActiveModel::Type::UnsignedInteger
|
58
63
|
Value = ActiveModel::Type::Value
|
59
64
|
|
60
65
|
register(:big_integer, Type::BigInteger, override: false)
|
@@ -65,6 +70,7 @@ module ActiveRecord
|
|
65
70
|
register(:decimal, Type::Decimal, override: false)
|
66
71
|
register(:float, Type::Float, override: false)
|
67
72
|
register(:integer, Type::Integer, override: false)
|
73
|
+
register(:json, Type::Json, override: false)
|
68
74
|
register(:string, Type::String, override: false)
|
69
75
|
register(:text, Type::Text, override: false)
|
70
76
|
register(:time, Type::Time, override: false)
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module ActiveRecord
|
2
4
|
module TypeCaster
|
3
5
|
class Connection # :nodoc:
|
@@ -6,24 +8,27 @@ module ActiveRecord
|
|
6
8
|
@table_name = table_name
|
7
9
|
end
|
8
10
|
|
9
|
-
def type_cast_for_database(
|
11
|
+
def type_cast_for_database(attr_name, value)
|
10
12
|
return value if value.is_a?(Arel::Nodes::BindParam)
|
11
|
-
|
12
|
-
|
13
|
+
type = type_for_attribute(attr_name)
|
14
|
+
type.serialize(value)
|
13
15
|
end
|
14
16
|
|
15
|
-
|
16
|
-
|
17
|
-
attr_reader :table_name
|
18
|
-
delegate :connection, to: :@klass
|
19
|
-
|
20
|
-
private
|
17
|
+
def type_for_attribute(attr_name)
|
18
|
+
schema_cache = connection.schema_cache
|
21
19
|
|
22
|
-
|
23
|
-
|
24
|
-
connection.
|
20
|
+
if schema_cache.data_source_exists?(table_name)
|
21
|
+
column = schema_cache.columns_hash(table_name)[attr_name.to_s]
|
22
|
+
type = connection.lookup_cast_type_from_column(column) if column
|
25
23
|
end
|
24
|
+
|
25
|
+
type || Type.default_value
|
26
26
|
end
|
27
|
+
|
28
|
+
delegate :connection, to: :@klass, private: true
|
29
|
+
|
30
|
+
private
|
31
|
+
attr_reader :table_name
|
27
32
|
end
|
28
33
|
end
|
29
34
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module ActiveRecord
|
2
4
|
module TypeCaster
|
3
5
|
class Map # :nodoc:
|
@@ -7,13 +9,12 @@ module ActiveRecord
|
|
7
9
|
|
8
10
|
def type_cast_for_database(attr_name, value)
|
9
11
|
return value if value.is_a?(Arel::Nodes::BindParam)
|
10
|
-
type = types.type_for_attribute(attr_name
|
12
|
+
type = types.type_for_attribute(attr_name)
|
11
13
|
type.serialize(value)
|
12
14
|
end
|
13
15
|
|
14
|
-
|
15
|
-
|
16
|
-
attr_reader :types
|
16
|
+
private
|
17
|
+
attr_reader :types
|
17
18
|
end
|
18
19
|
end
|
19
20
|
end
|
@@ -1,5 +1,7 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "active_record/type_caster/map"
|
4
|
+
require "active_record/type_caster/connection"
|
3
5
|
|
4
6
|
module ActiveRecord
|
5
7
|
module TypeCaster # :nodoc:
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module ActiveRecord
|
2
4
|
module Validations
|
3
5
|
class AssociatedValidator < ActiveModel::EachValidator #:nodoc:
|
@@ -37,7 +39,7 @@ module ActiveRecord
|
|
37
39
|
#
|
38
40
|
# * <tt>:message</tt> - A custom error message (default is: "is invalid").
|
39
41
|
# * <tt>:on</tt> - Specifies the contexts where this validation is active.
|
40
|
-
# Runs in all validation contexts by default
|
42
|
+
# Runs in all validation contexts by default +nil+. You can pass a symbol
|
41
43
|
# or an array of symbols. (e.g. <tt>on: :create</tt> or
|
42
44
|
# <tt>on: :custom_validation_context</tt> or
|
43
45
|
# <tt>on: [:create, :custom_validation_context]</tt>)
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module ActiveRecord
|
2
4
|
module Validations
|
3
5
|
class PresenceValidator < ActiveModel::Validations::PresenceValidator # :nodoc:
|
@@ -44,7 +46,7 @@ module ActiveRecord
|
|
44
46
|
# Configuration options:
|
45
47
|
# * <tt>:message</tt> - A custom error message (default is: "can't be blank").
|
46
48
|
# * <tt>:on</tt> - Specifies the contexts where this validation is active.
|
47
|
-
# Runs in all validation contexts by default
|
49
|
+
# Runs in all validation contexts by default +nil+. You can pass a symbol
|
48
50
|
# or an array of symbols. (e.g. <tt>on: :create</tt> or
|
49
51
|
# <tt>on: :custom_validation_context</tt> or
|
50
52
|
# <tt>on: [:create, :custom_validation_context]</tt>)
|
@@ -57,7 +59,7 @@ module ActiveRecord
|
|
57
59
|
# or <tt>unless: Proc.new { |user| user.signup_step <= 2 }</tt>). The method,
|
58
60
|
# proc or string should return or evaluate to a +true+ or +false+ value.
|
59
61
|
# * <tt>:strict</tt> - Specifies whether validation should be strict.
|
60
|
-
# See ActiveModel::
|
62
|
+
# See ActiveModel::Validations#validates! for more information.
|
61
63
|
def validates_presence_of(*attr_names)
|
62
64
|
validates_with PresenceValidator, _merge_attributes(attr_names)
|
63
65
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module ActiveRecord
|
2
4
|
module Validations
|
3
5
|
class UniquenessValidator < ActiveModel::EachValidator # :nodoc:
|
@@ -6,24 +8,27 @@ module ActiveRecord
|
|
6
8
|
raise ArgumentError, "#{options[:conditions]} was passed as :conditions but is not callable. " \
|
7
9
|
"Pass a callable instead: `conditions: -> { where(approved: true) }`"
|
8
10
|
end
|
9
|
-
|
11
|
+
unless Array(options[:scope]).all? { |scope| scope.respond_to?(:to_sym) }
|
12
|
+
raise ArgumentError, "#{options[:scope]} is not supported format for :scope option. " \
|
13
|
+
"Pass a symbol or an array of symbols instead: `scope: :user_id`"
|
14
|
+
end
|
15
|
+
super
|
10
16
|
@klass = options[:class]
|
11
17
|
end
|
12
18
|
|
13
19
|
def validate_each(record, attribute, value)
|
14
20
|
finder_class = find_finder_class_for(record)
|
15
|
-
table = finder_class.arel_table
|
16
21
|
value = map_enum_attribute(finder_class, attribute, value)
|
17
22
|
|
18
|
-
relation = build_relation(finder_class,
|
23
|
+
relation = build_relation(finder_class, attribute, value)
|
19
24
|
if record.persisted?
|
20
25
|
if finder_class.primary_key
|
21
|
-
relation = relation.where.not(finder_class.primary_key => record.
|
26
|
+
relation = relation.where.not(finder_class.primary_key => record.id_in_database)
|
22
27
|
else
|
23
|
-
raise UnknownPrimaryKey.new(finder_class, "
|
28
|
+
raise UnknownPrimaryKey.new(finder_class, "Cannot validate uniqueness for persisted record without primary key.")
|
24
29
|
end
|
25
30
|
end
|
26
|
-
relation = scope_relation(record,
|
31
|
+
relation = scope_relation(record, relation)
|
27
32
|
relation = relation.merge(options[:conditions]) if options[:conditions]
|
28
33
|
|
29
34
|
if relation.exists?
|
@@ -34,13 +39,13 @@ module ActiveRecord
|
|
34
39
|
end
|
35
40
|
end
|
36
41
|
|
37
|
-
|
42
|
+
private
|
38
43
|
# The check for an existing value should be run from a class that
|
39
44
|
# isn't abstract. This means working down from the current class
|
40
45
|
# (self), to the first non-abstract class. Since classes don't know
|
41
46
|
# their subclasses, we have to build the hierarchy between self and
|
42
47
|
# the record's class.
|
43
|
-
def find_finder_class_for(record)
|
48
|
+
def find_finder_class_for(record)
|
44
49
|
class_hierarchy = [record.class]
|
45
50
|
|
46
51
|
while class_hierarchy.first != @klass
|
@@ -50,41 +55,25 @@ module ActiveRecord
|
|
50
55
|
class_hierarchy.detect { |klass| !klass.abstract_class? }
|
51
56
|
end
|
52
57
|
|
53
|
-
def build_relation(klass,
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
end
|
58
|
+
def build_relation(klass, attribute, value)
|
59
|
+
relation = klass.unscoped
|
60
|
+
comparison = relation.bind_attribute(attribute, value) do |attr, bind|
|
61
|
+
return relation.none! if bind.unboundable?
|
58
62
|
|
59
|
-
|
60
|
-
|
61
|
-
|
63
|
+
if !options.key?(:case_sensitive) || bind.nil?
|
64
|
+
klass.connection.default_uniqueness_comparison(attr, bind, klass)
|
65
|
+
elsif options[:case_sensitive]
|
66
|
+
klass.connection.case_sensitive_comparison(attr, bind)
|
67
|
+
else
|
68
|
+
# will use SQL LOWER function before comparison, unless it detects a case insensitive collation
|
69
|
+
klass.connection.case_insensitive_comparison(attr, bind)
|
70
|
+
end
|
62
71
|
end
|
63
72
|
|
64
|
-
|
65
|
-
|
66
|
-
column = klass.columns_hash[attribute_name]
|
67
|
-
cast_type = klass.type_for_attribute(attribute_name)
|
68
|
-
value = cast_type.serialize(value)
|
69
|
-
value = klass.connection.type_cast(value)
|
70
|
-
|
71
|
-
comparison = if !options[:case_sensitive] && !value.nil?
|
72
|
-
# will use SQL LOWER function before comparison, unless it detects a case insensitive collation
|
73
|
-
klass.connection.case_insensitive_comparison(table, attribute, column, value)
|
74
|
-
else
|
75
|
-
klass.connection.case_sensitive_comparison(table, attribute, column, value)
|
76
|
-
end
|
77
|
-
if value.nil?
|
78
|
-
klass.unscoped.where(comparison)
|
79
|
-
else
|
80
|
-
bind = Relation::QueryAttribute.new(attribute_name, value, Type::Value.new)
|
81
|
-
klass.unscoped.where(comparison, bind)
|
82
|
-
end
|
83
|
-
rescue RangeError
|
84
|
-
klass.none
|
73
|
+
relation.where!(comparison)
|
85
74
|
end
|
86
75
|
|
87
|
-
def scope_relation(record,
|
76
|
+
def scope_relation(record, relation)
|
88
77
|
Array(options[:scope]).each do |scope_item|
|
89
78
|
scope_value = if record.class._reflect_on_association(scope_item)
|
90
79
|
record.association(scope_item).reader
|
@@ -204,9 +193,7 @@ module ActiveRecord
|
|
204
193
|
# | # Boom! We now have a duplicate
|
205
194
|
# | # title!
|
206
195
|
#
|
207
|
-
#
|
208
|
-
# isolation level. The best way to work around this problem is to add a unique
|
209
|
-
# index to the database table using
|
196
|
+
# The best way to work around this problem is to add a unique index to the database table using
|
210
197
|
# {connection.add_index}[rdoc-ref:ConnectionAdapters::SchemaStatements#add_index].
|
211
198
|
# In the rare case that a race condition occurs, the database will guarantee
|
212
199
|
# the field's uniqueness.
|
@@ -218,7 +205,7 @@ module ActiveRecord
|
|
218
205
|
# can catch it and restart the transaction (e.g. by telling the user
|
219
206
|
# that the title already exists, and asking them to re-enter the title).
|
220
207
|
# This technique is also known as
|
221
|
-
# {optimistic concurrency control}[
|
208
|
+
# {optimistic concurrency control}[https://en.wikipedia.org/wiki/Optimistic_concurrency_control].
|
222
209
|
#
|
223
210
|
# The bundled ActiveRecord::ConnectionAdapters distinguish unique index
|
224
211
|
# constraint errors from other types of database errors by throwing an
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module ActiveRecord
|
2
4
|
# = Active Record \RecordInvalid
|
3
5
|
#
|
@@ -38,15 +40,16 @@ module ActiveRecord
|
|
38
40
|
include ActiveModel::Validations
|
39
41
|
|
40
42
|
# The validation process on save can be skipped by passing <tt>validate: false</tt>.
|
43
|
+
# The validation context can be changed by passing <tt>context: context</tt>.
|
41
44
|
# The regular {ActiveRecord::Base#save}[rdoc-ref:Persistence#save] method is replaced
|
42
45
|
# with this when the validations module is mixed in, which it is by default.
|
43
|
-
def save(options={})
|
46
|
+
def save(options = {})
|
44
47
|
perform_validations(options) ? super : false
|
45
48
|
end
|
46
49
|
|
47
50
|
# Attempts to save the record just like {ActiveRecord::Base#save}[rdoc-ref:Base#save] but
|
48
51
|
# will raise an ActiveRecord::RecordInvalid exception instead of returning +false+ if the record is not valid.
|
49
|
-
def save!(options={})
|
52
|
+
def save!(options = {})
|
50
53
|
perform_validations(options) ? super : raise_validation_error
|
51
54
|
end
|
52
55
|
|
@@ -68,7 +71,7 @@ module ActiveRecord
|
|
68
71
|
|
69
72
|
alias_method :validate, :valid?
|
70
73
|
|
71
|
-
|
74
|
+
private
|
72
75
|
|
73
76
|
def default_validation_context
|
74
77
|
new_record? ? :create : :update
|
@@ -78,7 +81,7 @@ module ActiveRecord
|
|
78
81
|
raise(RecordInvalid.new(self))
|
79
82
|
end
|
80
83
|
|
81
|
-
def perform_validations(options={})
|
84
|
+
def perform_validations(options = {})
|
82
85
|
options[:validate] == false || valid?(options[:context])
|
83
86
|
end
|
84
87
|
end
|
data/lib/active_record.rb
CHANGED
@@ -1,5 +1,7 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
#--
|
2
|
-
# Copyright (c) 2004-
|
4
|
+
# Copyright (c) 2004-2019 David Heinemeier Hansson
|
3
5
|
#
|
4
6
|
# Permission is hereby granted, free of charge, to any person obtaining
|
5
7
|
# a copy of this software and associated documentation files (the
|
@@ -21,18 +23,18 @@
|
|
21
23
|
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
22
24
|
#++
|
23
25
|
|
24
|
-
require
|
25
|
-
require
|
26
|
-
require
|
27
|
-
require
|
26
|
+
require "active_support"
|
27
|
+
require "active_support/rails"
|
28
|
+
require "active_model"
|
29
|
+
require "arel"
|
30
|
+
require "yaml"
|
28
31
|
|
29
|
-
require
|
30
|
-
require
|
32
|
+
require "active_record/version"
|
33
|
+
require "active_model/attribute_set"
|
31
34
|
|
32
35
|
module ActiveRecord
|
33
36
|
extend ActiveSupport::Autoload
|
34
37
|
|
35
|
-
autoload :Attribute
|
36
38
|
autoload :Base
|
37
39
|
autoload :Callbacks
|
38
40
|
autoload :Core
|
@@ -45,7 +47,7 @@ module ActiveRecord
|
|
45
47
|
autoload :Inheritance
|
46
48
|
autoload :Integration
|
47
49
|
autoload :Migration
|
48
|
-
autoload :Migrator,
|
50
|
+
autoload :Migrator, "active_record/migration"
|
49
51
|
autoload :ModelSchema
|
50
52
|
autoload :NestedAttributes
|
51
53
|
autoload :NoTouching
|
@@ -53,9 +55,8 @@ module ActiveRecord
|
|
53
55
|
autoload :Persistence
|
54
56
|
autoload :QueryCache
|
55
57
|
autoload :Querying
|
56
|
-
autoload :CollectionCacheKey
|
57
58
|
autoload :ReadonlyAttributes
|
58
|
-
autoload :RecordInvalid,
|
59
|
+
autoload :RecordInvalid, "active_record/validations"
|
59
60
|
autoload :Reflection
|
60
61
|
autoload :RuntimeRegistry
|
61
62
|
autoload :Sanitization
|
@@ -72,11 +73,12 @@ module ActiveRecord
|
|
72
73
|
autoload :Translation
|
73
74
|
autoload :Validations
|
74
75
|
autoload :SecureToken
|
76
|
+
autoload :DatabaseSelector, "active_record/middleware/database_selector"
|
75
77
|
|
76
78
|
eager_autoload do
|
77
|
-
autoload :ActiveRecordError,
|
78
|
-
autoload :ConnectionNotEstablished,
|
79
|
-
autoload :ConnectionAdapters,
|
79
|
+
autoload :ActiveRecordError, "active_record/errors"
|
80
|
+
autoload :ConnectionNotEstablished, "active_record/errors"
|
81
|
+
autoload :ConnectionAdapters, "active_record/connection_adapters/abstract_adapter"
|
80
82
|
|
81
83
|
autoload :Aggregations
|
82
84
|
autoload :Associations
|
@@ -90,7 +92,7 @@ module ActiveRecord
|
|
90
92
|
autoload :AssociationRelation
|
91
93
|
autoload :NullRelation
|
92
94
|
|
93
|
-
autoload_under
|
95
|
+
autoload_under "relation" do
|
94
96
|
autoload :QueryMethods
|
95
97
|
autoload :FinderMethods
|
96
98
|
autoload :Calculations
|
@@ -102,11 +104,12 @@ module ActiveRecord
|
|
102
104
|
|
103
105
|
autoload :Result
|
104
106
|
autoload :TableMetadata
|
107
|
+
autoload :Type
|
105
108
|
end
|
106
109
|
|
107
110
|
module Coders
|
108
|
-
autoload :YAMLColumn,
|
109
|
-
autoload :JSON,
|
111
|
+
autoload :YAMLColumn, "active_record/coders/yaml_column"
|
112
|
+
autoload :JSON, "active_record/coders/json"
|
110
113
|
end
|
111
114
|
|
112
115
|
module AttributeMethods
|
@@ -150,17 +153,24 @@ module ActiveRecord
|
|
150
153
|
end
|
151
154
|
end
|
152
155
|
|
156
|
+
module Middleware
|
157
|
+
extend ActiveSupport::Autoload
|
158
|
+
|
159
|
+
autoload :DatabaseSelector, "active_record/middleware/database_selector"
|
160
|
+
end
|
161
|
+
|
153
162
|
module Tasks
|
154
163
|
extend ActiveSupport::Autoload
|
155
164
|
|
156
165
|
autoload :DatabaseTasks
|
157
|
-
autoload :SQLiteDatabaseTasks,
|
158
|
-
autoload :MySQLDatabaseTasks,
|
166
|
+
autoload :SQLiteDatabaseTasks, "active_record/tasks/sqlite_database_tasks"
|
167
|
+
autoload :MySQLDatabaseTasks, "active_record/tasks/mysql_database_tasks"
|
159
168
|
autoload :PostgreSQLDatabaseTasks,
|
160
|
-
|
169
|
+
"active_record/tasks/postgresql_database_tasks"
|
161
170
|
end
|
162
171
|
|
163
|
-
autoload :
|
172
|
+
autoload :TestDatabases, "active_record/test_databases"
|
173
|
+
autoload :TestFixtures, "active_record/fixtures"
|
164
174
|
|
165
175
|
def self.eager_load!
|
166
176
|
super
|
@@ -177,5 +187,9 @@ ActiveSupport.on_load(:active_record) do
|
|
177
187
|
end
|
178
188
|
|
179
189
|
ActiveSupport.on_load(:i18n) do
|
180
|
-
I18n.load_path << File.
|
190
|
+
I18n.load_path << File.expand_path("active_record/locale/en.yml", __dir__)
|
181
191
|
end
|
192
|
+
|
193
|
+
YAML.load_tags["!ruby/object:ActiveRecord::AttributeSet"] = "ActiveModel::AttributeSet"
|
194
|
+
YAML.load_tags["!ruby/object:ActiveRecord::Attribute::FromDatabase"] = "ActiveModel::Attribute::FromDatabase"
|
195
|
+
YAML.load_tags["!ruby/object:ActiveRecord::LazyAttributeHash"] = "ActiveModel::LazyAttributeHash"
|
@@ -0,0 +1,37 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Arel # :nodoc: all
|
4
|
+
module Attributes
|
5
|
+
class Attribute < Struct.new :relation, :name
|
6
|
+
include Arel::Expressions
|
7
|
+
include Arel::Predications
|
8
|
+
include Arel::AliasPredication
|
9
|
+
include Arel::OrderPredications
|
10
|
+
include Arel::Math
|
11
|
+
|
12
|
+
###
|
13
|
+
# Create a node for lowering this attribute
|
14
|
+
def lower
|
15
|
+
relation.lower self
|
16
|
+
end
|
17
|
+
|
18
|
+
def type_cast_for_database(value)
|
19
|
+
relation.type_cast_for_database(name, value)
|
20
|
+
end
|
21
|
+
|
22
|
+
def able_to_type_cast?
|
23
|
+
relation.able_to_type_cast?
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
class String < Attribute; end
|
28
|
+
class Time < Attribute; end
|
29
|
+
class Boolean < Attribute; end
|
30
|
+
class Decimal < Attribute; end
|
31
|
+
class Float < Attribute; end
|
32
|
+
class Integer < Attribute; end
|
33
|
+
class Undefined < Attribute; end
|
34
|
+
end
|
35
|
+
|
36
|
+
Attribute = Attributes::Attribute
|
37
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "arel/attributes/attribute"
|
4
|
+
|
5
|
+
module Arel # :nodoc: all
|
6
|
+
module Attributes
|
7
|
+
###
|
8
|
+
# Factory method to wrap a raw database +column+ to an Arel Attribute.
|
9
|
+
def self.for(column)
|
10
|
+
case column.type
|
11
|
+
when :string, :text, :binary then String
|
12
|
+
when :integer then Integer
|
13
|
+
when :float then Float
|
14
|
+
when :decimal then Decimal
|
15
|
+
when :date, :datetime, :timestamp, :time then Time
|
16
|
+
when :boolean then Boolean
|
17
|
+
else
|
18
|
+
Undefined
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|