activerecord 5.0.7.2 → 6.1.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 +4 -4
- data/CHANGELOG.md +829 -2015
- data/MIT-LICENSE +3 -1
- data/README.rdoc +11 -9
- data/examples/performance.rb +31 -29
- data/examples/simple.rb +5 -3
- data/lib/active_record.rb +37 -29
- data/lib/active_record/aggregations.rb +249 -247
- data/lib/active_record/association_relation.rb +30 -18
- data/lib/active_record/associations.rb +1714 -1596
- data/lib/active_record/associations/alias_tracker.rb +36 -42
- data/lib/active_record/associations/association.rb +143 -68
- data/lib/active_record/associations/association_scope.rb +98 -94
- data/lib/active_record/associations/belongs_to_association.rb +76 -46
- data/lib/active_record/associations/belongs_to_polymorphic_association.rb +13 -12
- data/lib/active_record/associations/builder/association.rb +27 -28
- data/lib/active_record/associations/builder/belongs_to.rb +52 -60
- data/lib/active_record/associations/builder/collection_association.rb +12 -22
- data/lib/active_record/associations/builder/has_and_belongs_to_many.rb +40 -62
- data/lib/active_record/associations/builder/has_many.rb +10 -2
- data/lib/active_record/associations/builder/has_one.rb +35 -2
- data/lib/active_record/associations/builder/singular_association.rb +5 -1
- data/lib/active_record/associations/collection_association.rb +104 -259
- data/lib/active_record/associations/collection_proxy.rb +169 -125
- data/lib/active_record/associations/foreign_association.rb +22 -0
- data/lib/active_record/associations/has_many_association.rb +46 -31
- data/lib/active_record/associations/has_many_through_association.rb +66 -46
- data/lib/active_record/associations/has_one_association.rb +71 -52
- data/lib/active_record/associations/has_one_through_association.rb +20 -11
- data/lib/active_record/associations/join_dependency.rb +169 -180
- data/lib/active_record/associations/join_dependency/join_association.rb +53 -79
- 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/preloader.rb +97 -104
- data/lib/active_record/associations/preloader/association.rb +109 -97
- data/lib/active_record/associations/preloader/through_association.rb +77 -76
- data/lib/active_record/associations/singular_association.rb +12 -45
- data/lib/active_record/associations/through_association.rb +27 -15
- data/lib/active_record/attribute_assignment.rb +55 -60
- data/lib/active_record/attribute_methods.rb +111 -141
- data/lib/active_record/attribute_methods/before_type_cast.rb +17 -9
- data/lib/active_record/attribute_methods/dirty.rb +172 -112
- data/lib/active_record/attribute_methods/primary_key.rb +88 -91
- data/lib/active_record/attribute_methods/query.rb +6 -8
- data/lib/active_record/attribute_methods/read.rb +18 -50
- data/lib/active_record/attribute_methods/serialization.rb +38 -10
- data/lib/active_record/attribute_methods/time_zone_conversion.rb +38 -66
- data/lib/active_record/attribute_methods/write.rb +25 -32
- data/lib/active_record/attributes.rb +69 -31
- data/lib/active_record/autosave_association.rb +102 -66
- data/lib/active_record/base.rb +16 -25
- data/lib/active_record/callbacks.rb +202 -43
- data/lib/active_record/coders/json.rb +2 -0
- data/lib/active_record/coders/yaml_column.rb +11 -12
- data/lib/active_record/connection_adapters.rb +50 -0
- data/lib/active_record/connection_adapters/abstract/connection_pool.rb +661 -375
- data/lib/active_record/connection_adapters/abstract/database_limits.rb +14 -38
- data/lib/active_record/connection_adapters/abstract/database_statements.rb +269 -105
- data/lib/active_record/connection_adapters/abstract/query_cache.rb +54 -35
- data/lib/active_record/connection_adapters/abstract/quoting.rb +137 -93
- data/lib/active_record/connection_adapters/abstract/savepoints.rb +5 -3
- data/lib/active_record/connection_adapters/abstract/schema_creation.rb +155 -113
- data/lib/active_record/connection_adapters/abstract/schema_definitions.rb +328 -162
- data/lib/active_record/connection_adapters/abstract/schema_dumper.rb +68 -80
- data/lib/active_record/connection_adapters/abstract/schema_statements.rb +591 -259
- data/lib/active_record/connection_adapters/abstract/transaction.rb +229 -91
- data/lib/active_record/connection_adapters/abstract_adapter.rb +392 -244
- data/lib/active_record/connection_adapters/abstract_mysql_adapter.rb +457 -582
- data/lib/active_record/connection_adapters/column.rb +55 -13
- data/lib/active_record/connection_adapters/deduplicable.rb +29 -0
- data/lib/active_record/connection_adapters/legacy_pool_manager.rb +31 -0
- data/lib/active_record/connection_adapters/mysql/column.rb +8 -31
- data/lib/active_record/connection_adapters/mysql/database_statements.rb +135 -49
- data/lib/active_record/connection_adapters/mysql/explain_pretty_printer.rb +24 -23
- data/lib/active_record/connection_adapters/mysql/quoting.rb +50 -20
- data/lib/active_record/connection_adapters/mysql/schema_creation.rb +79 -49
- data/lib/active_record/connection_adapters/mysql/schema_definitions.rb +66 -56
- data/lib/active_record/connection_adapters/mysql/schema_dumper.rb +70 -36
- data/lib/active_record/connection_adapters/mysql/schema_statements.rb +268 -0
- data/lib/active_record/connection_adapters/mysql/type_metadata.rb +20 -12
- data/lib/active_record/connection_adapters/mysql2_adapter.rb +74 -37
- data/lib/active_record/connection_adapters/pool_config.rb +63 -0
- data/lib/active_record/connection_adapters/pool_manager.rb +43 -0
- data/lib/active_record/connection_adapters/postgresql/column.rb +39 -28
- data/lib/active_record/connection_adapters/postgresql/database_statements.rb +70 -101
- data/lib/active_record/connection_adapters/postgresql/explain_pretty_printer.rb +5 -3
- data/lib/active_record/connection_adapters/postgresql/oid.rb +26 -21
- data/lib/active_record/connection_adapters/postgresql/oid/array.rb +22 -11
- 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 +6 -6
- data/lib/active_record/connection_adapters/postgresql/oid/date.rb +23 -0
- data/lib/active_record/connection_adapters/postgresql/oid/date_time.rb +14 -4
- 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 +19 -18
- data/lib/active_record/connection_adapters/postgresql/oid/inet.rb +2 -0
- data/lib/active_record/connection_adapters/postgresql/oid/interval.rb +49 -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/macaddr.rb +25 -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 +30 -9
- data/lib/active_record/connection_adapters/postgresql/oid/range.rb +52 -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 +18 -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/quoting.rb +98 -38
- data/lib/active_record/connection_adapters/postgresql/referential_integrity.rb +21 -27
- data/lib/active_record/connection_adapters/postgresql/schema_creation.rb +80 -0
- data/lib/active_record/connection_adapters/postgresql/schema_definitions.rb +147 -105
- data/lib/active_record/connection_adapters/postgresql/schema_dumper.rb +34 -32
- data/lib/active_record/connection_adapters/postgresql/schema_statements.rb +426 -324
- data/lib/active_record/connection_adapters/postgresql/type_metadata.rb +32 -23
- data/lib/active_record/connection_adapters/postgresql/utils.rb +9 -6
- data/lib/active_record/connection_adapters/postgresql_adapter.rb +418 -293
- data/lib/active_record/connection_adapters/schema_cache.rb +135 -18
- data/lib/active_record/connection_adapters/sql_type_metadata.rb +22 -7
- data/lib/active_record/connection_adapters/sqlite3/database_statements.rb +144 -0
- data/lib/active_record/connection_adapters/sqlite3/explain_pretty_printer.rb +3 -1
- data/lib/active_record/connection_adapters/sqlite3/quoting.rb +72 -18
- data/lib/active_record/connection_adapters/sqlite3/schema_creation.rb +5 -6
- 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 +170 -0
- data/lib/active_record/connection_adapters/sqlite3_adapter.rb +282 -290
- data/lib/active_record/connection_adapters/statement_pool.rb +9 -8
- data/lib/active_record/connection_handling.rb +287 -45
- data/lib/active_record/core.rb +385 -181
- data/lib/active_record/counter_cache.rb +60 -28
- data/lib/active_record/database_configurations.rb +272 -0
- data/lib/active_record/database_configurations/connection_url_resolver.rb +98 -0
- data/lib/active_record/database_configurations/database_config.rb +80 -0
- data/lib/active_record/database_configurations/hash_config.rb +96 -0
- data/lib/active_record/database_configurations/url_config.rb +53 -0
- data/lib/active_record/delegated_type.rb +209 -0
- data/lib/active_record/destroy_association_async_job.rb +36 -0
- data/lib/active_record/dynamic_matchers.rb +87 -87
- data/lib/active_record/enum.rb +122 -47
- data/lib/active_record/errors.rb +153 -22
- data/lib/active_record/explain.rb +13 -8
- 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 +20 -22
- data/lib/active_record/fixture_set/model_metadata.rb +32 -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 +246 -507
- data/lib/active_record/gem_version.rb +6 -4
- data/lib/active_record/inheritance.rb +168 -95
- data/lib/active_record/insert_all.rb +208 -0
- data/lib/active_record/integration.rb +114 -25
- data/lib/active_record/internal_metadata.rb +30 -24
- data/lib/active_record/legacy_yaml_adapter.rb +11 -5
- data/lib/active_record/locking/optimistic.rb +81 -85
- data/lib/active_record/locking/pessimistic.rb +22 -6
- data/lib/active_record/log_subscriber.rb +68 -31
- data/lib/active_record/middleware/database_selector.rb +77 -0
- data/lib/active_record/middleware/database_selector/resolver.rb +92 -0
- data/lib/active_record/middleware/database_selector/resolver/session.rb +48 -0
- data/lib/active_record/migration.rb +439 -342
- data/lib/active_record/migration/command_recorder.rb +152 -98
- data/lib/active_record/migration/compatibility.rb +229 -60
- data/lib/active_record/migration/join_table.rb +8 -7
- data/lib/active_record/model_schema.rb +230 -122
- data/lib/active_record/nested_attributes.rb +213 -203
- data/lib/active_record/no_touching.rb +11 -2
- data/lib/active_record/null_relation.rb +12 -34
- data/lib/active_record/persistence.rb +471 -97
- data/lib/active_record/query_cache.rb +23 -12
- data/lib/active_record/querying.rb +43 -25
- data/lib/active_record/railtie.rb +155 -43
- 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 +507 -195
- data/lib/active_record/readonly_attributes.rb +9 -4
- data/lib/active_record/reflection.rb +245 -269
- data/lib/active_record/relation.rb +475 -324
- data/lib/active_record/relation/batches.rb +125 -72
- data/lib/active_record/relation/batches/batch_enumerator.rb +28 -10
- data/lib/active_record/relation/calculations.rb +267 -171
- data/lib/active_record/relation/delegation.rb +73 -69
- data/lib/active_record/relation/finder_methods.rb +238 -248
- data/lib/active_record/relation/from_clause.rb +7 -9
- data/lib/active_record/relation/merger.rb +95 -77
- data/lib/active_record/relation/predicate_builder.rb +109 -110
- data/lib/active_record/relation/predicate_builder/array_handler.rb +22 -17
- data/lib/active_record/relation/predicate_builder/association_query_value.rb +42 -0
- data/lib/active_record/relation/predicate_builder/basic_object_handler.rb +6 -4
- data/lib/active_record/relation/predicate_builder/polymorphic_array_value.rb +55 -0
- data/lib/active_record/relation/predicate_builder/range_handler.rb +7 -18
- data/lib/active_record/relation/predicate_builder/relation_handler.rb +7 -1
- data/lib/active_record/relation/query_attribute.rb +33 -2
- data/lib/active_record/relation/query_methods.rb +654 -374
- data/lib/active_record/relation/record_fetch_warning.rb +8 -6
- data/lib/active_record/relation/spawn_methods.rb +15 -14
- data/lib/active_record/relation/where_clause.rb +171 -109
- data/lib/active_record/result.rb +88 -51
- data/lib/active_record/runtime_registry.rb +5 -3
- data/lib/active_record/sanitization.rb +73 -100
- data/lib/active_record/schema.rb +7 -14
- data/lib/active_record/schema_dumper.rb +101 -69
- data/lib/active_record/schema_migration.rb +16 -12
- data/lib/active_record/scoping.rb +20 -20
- data/lib/active_record/scoping/default.rb +92 -95
- data/lib/active_record/scoping/named.rb +39 -30
- data/lib/active_record/secure_token.rb +19 -9
- data/lib/active_record/serialization.rb +7 -3
- data/lib/active_record/signed_id.rb +116 -0
- data/lib/active_record/statement_cache.rb +80 -29
- data/lib/active_record/store.rb +122 -42
- data/lib/active_record/suppressor.rb +6 -3
- data/lib/active_record/table_metadata.rb +51 -39
- data/lib/active_record/tasks/database_tasks.rb +332 -115
- data/lib/active_record/tasks/mysql_database_tasks.rb +66 -104
- data/lib/active_record/tasks/postgresql_database_tasks.rb +84 -56
- data/lib/active_record/tasks/sqlite_database_tasks.rb +40 -19
- data/lib/active_record/test_databases.rb +24 -0
- data/lib/active_record/test_fixtures.rb +246 -0
- data/lib/active_record/timestamp.rb +70 -38
- data/lib/active_record/touch_later.rb +26 -24
- data/lib/active_record/transactions.rb +121 -184
- data/lib/active_record/translation.rb +3 -1
- data/lib/active_record/type.rb +29 -17
- data/lib/active_record/type/adapter_specific_registry.rb +44 -48
- 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 -4
- 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 +20 -9
- data/lib/active_record/type/text.rb +11 -0
- data/lib/active_record/type/time.rb +12 -1
- data/lib/active_record/type/type_map.rb +14 -17
- data/lib/active_record/type/unsigned_integer.rb +16 -0
- data/lib/active_record/type_caster.rb +4 -2
- data/lib/active_record/type_caster/connection.rb +17 -13
- data/lib/active_record/type_caster/map.rb +10 -6
- data/lib/active_record/validations.rb +8 -5
- data/lib/active_record/validations/absence.rb +2 -0
- data/lib/active_record/validations/associated.rb +4 -3
- data/lib/active_record/validations/length.rb +2 -0
- data/lib/active_record/validations/numericality.rb +35 -0
- data/lib/active_record/validations/presence.rb +4 -2
- data/lib/active_record/validations/uniqueness.rb +52 -45
- data/lib/active_record/version.rb +3 -1
- data/lib/arel.rb +54 -0
- data/lib/arel/alias_predication.rb +9 -0
- data/lib/arel/attributes/attribute.rb +41 -0
- data/lib/arel/collectors/bind.rb +29 -0
- data/lib/arel/collectors/composite.rb +39 -0
- data/lib/arel/collectors/plain_string.rb +20 -0
- data/lib/arel/collectors/sql_string.rb +27 -0
- data/lib/arel/collectors/substitute_binds.rb +35 -0
- data/lib/arel/crud.rb +42 -0
- data/lib/arel/delete_manager.rb +18 -0
- data/lib/arel/errors.rb +9 -0
- data/lib/arel/expressions.rb +29 -0
- data/lib/arel/factory_methods.rb +49 -0
- data/lib/arel/insert_manager.rb +49 -0
- data/lib/arel/math.rb +45 -0
- data/lib/arel/nodes.rb +70 -0
- data/lib/arel/nodes/and.rb +32 -0
- data/lib/arel/nodes/ascending.rb +23 -0
- data/lib/arel/nodes/binary.rb +126 -0
- data/lib/arel/nodes/bind_param.rb +44 -0
- data/lib/arel/nodes/case.rb +55 -0
- data/lib/arel/nodes/casted.rb +62 -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 +15 -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 +11 -0
- data/lib/arel/nodes/homogeneous_in.rb +72 -0
- data/lib/arel/nodes/in.rb +15 -0
- data/lib/arel/nodes/infix_operation.rb +92 -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 +51 -0
- data/lib/arel/nodes/node_expression.rb +13 -0
- data/lib/arel/nodes/ordering.rb +27 -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 +19 -0
- data/lib/arel/nodes/string_join.rb +11 -0
- data/lib/arel/nodes/table_alias.rb +31 -0
- data/lib/arel/nodes/terminal.rb +16 -0
- data/lib/arel/nodes/true.rb +16 -0
- data/lib/arel/nodes/unary.rb +44 -0
- data/lib/arel/nodes/unary_operation.rb +20 -0
- data/lib/arel/nodes/unqualified_column.rb +22 -0
- data/lib/arel/nodes/update_statement.rb +41 -0
- data/lib/arel/nodes/values_list.rb +9 -0
- data/lib/arel/nodes/window.rb +126 -0
- data/lib/arel/nodes/with.rb +11 -0
- data/lib/arel/order_predications.rb +13 -0
- data/lib/arel/predications.rb +250 -0
- data/lib/arel/select_manager.rb +270 -0
- data/lib/arel/table.rb +118 -0
- data/lib/arel/tree_manager.rb +72 -0
- data/lib/arel/update_manager.rb +34 -0
- data/lib/arel/visitors.rb +13 -0
- data/lib/arel/visitors/dot.rb +308 -0
- data/lib/arel/visitors/mysql.rb +93 -0
- data/lib/arel/visitors/postgresql.rb +120 -0
- data/lib/arel/visitors/sqlite.rb +38 -0
- data/lib/arel/visitors/to_sql.rb +899 -0
- data/lib/arel/visitors/visitor.rb +45 -0
- data/lib/arel/window_predications.rb +9 -0
- data/lib/rails/generators/active_record.rb +7 -5
- data/lib/rails/generators/active_record/application_record/application_record_generator.rb +26 -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.rb +22 -3
- data/lib/rails/generators/active_record/migration/migration_generator.rb +38 -35
- data/lib/rails/generators/active_record/migration/templates/{create_table_migration.rb → create_table_migration.rb.tt} +3 -1
- data/lib/rails/generators/active_record/migration/templates/{migration.rb → migration.rb.tt} +7 -5
- data/lib/rails/generators/active_record/model/model_generator.rb +41 -25
- data/lib/rails/generators/active_record/model/templates/abstract_base_class.rb.tt +7 -0
- 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
- metadata +141 -57
- 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.rb +0 -213
- data/lib/active_record/attribute/user_provided_default.rb +0 -28
- data/lib/active_record/attribute_decorators.rb +0 -67
- data/lib/active_record/attribute_mutation_tracker.rb +0 -70
- data/lib/active_record/attribute_set.rb +0 -110
- data/lib/active_record/attribute_set/builder.rb +0 -132
- data/lib/active_record/collection_cache_key.rb +0 -50
- data/lib/active_record/connection_adapters/connection_specification.rb +0 -263
- data/lib/active_record/connection_adapters/determine_if_preparable_visitor.rb +0 -22
- 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/base_handler.rb +0 -17
- 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/relation/where_clause_factory.rb +0 -38
- data/lib/active_record/type/internal/abstract_json.rb +0 -33
@@ -1,11 +1,27 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module ActiveRecord
|
2
|
-
# = Active Record Through Association
|
3
4
|
module Associations
|
5
|
+
# = Active Record Through Association
|
4
6
|
module ThroughAssociation #:nodoc:
|
7
|
+
delegate :source_reflection, to: :reflection
|
8
|
+
|
9
|
+
private
|
10
|
+
def through_reflection
|
11
|
+
@through_reflection ||= begin
|
12
|
+
refl = reflection.through_reflection
|
5
13
|
|
6
|
-
|
14
|
+
while refl.through_reflection?
|
15
|
+
refl = refl.through_reflection
|
16
|
+
end
|
7
17
|
|
8
|
-
|
18
|
+
refl
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def through_association
|
23
|
+
@through_association ||= owner.association(through_reflection.name)
|
24
|
+
end
|
9
25
|
|
10
26
|
# We merge in these scopes for two reasons:
|
11
27
|
#
|
@@ -16,14 +32,12 @@ module ActiveRecord
|
|
16
32
|
reflection.chain.drop(1).each do |reflection|
|
17
33
|
relation = reflection.klass.scope_for_association
|
18
34
|
scope.merge!(
|
19
|
-
relation.except(:select, :create_with, :includes, :preload, :joins, :
|
35
|
+
relation.except(:select, :create_with, :includes, :preload, :eager_load, :joins, :left_outer_joins)
|
20
36
|
)
|
21
37
|
end
|
22
38
|
scope
|
23
39
|
end
|
24
40
|
|
25
|
-
private
|
26
|
-
|
27
41
|
# Construct attributes for :through pointing to owner and associate. This is used by the
|
28
42
|
# methods which create and delete records on the association.
|
29
43
|
#
|
@@ -39,24 +53,22 @@ module ActiveRecord
|
|
39
53
|
def construct_join_attributes(*records)
|
40
54
|
ensure_mutable
|
41
55
|
|
42
|
-
|
56
|
+
association_primary_key = source_reflection.association_primary_key(reflection.klass)
|
57
|
+
|
58
|
+
if association_primary_key == reflection.klass.primary_key && !options[:source_type]
|
43
59
|
join_attributes = { source_reflection.name => records }
|
44
60
|
else
|
45
61
|
join_attributes = {
|
46
|
-
source_reflection.foreign_key =>
|
47
|
-
records.map { |record|
|
48
|
-
record.send(source_reflection.association_primary_key(reflection.klass))
|
49
|
-
}
|
62
|
+
source_reflection.foreign_key => records.map(&association_primary_key.to_sym)
|
50
63
|
}
|
51
64
|
end
|
52
65
|
|
53
66
|
if options[:source_type]
|
54
|
-
join_attributes[source_reflection.foreign_type] =
|
55
|
-
records.map { |record| record.class.base_class.name }
|
67
|
+
join_attributes[source_reflection.foreign_type] = [ options[:source_type] ]
|
56
68
|
end
|
57
69
|
|
58
70
|
if records.count == 1
|
59
|
-
|
71
|
+
join_attributes.transform_values!(&:first)
|
60
72
|
else
|
61
73
|
join_attributes
|
62
74
|
end
|
@@ -102,7 +114,7 @@ module ActiveRecord
|
|
102
114
|
attributes[inverse.foreign_key] = target.id
|
103
115
|
end
|
104
116
|
|
105
|
-
super
|
117
|
+
super
|
106
118
|
end
|
107
119
|
end
|
108
120
|
end
|
@@ -1,55 +1,51 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "active_model/forbidden_attributes_protection"
|
2
4
|
|
3
5
|
module ActiveRecord
|
4
6
|
module AttributeAssignment
|
5
|
-
extend ActiveSupport::Concern
|
6
7
|
include ActiveModel::AttributeAssignment
|
7
8
|
|
8
|
-
# Alias for ActiveModel::AttributeAssignment#assign_attributes. See ActiveModel::AttributeAssignment.
|
9
|
-
def attributes=(attributes)
|
10
|
-
assign_attributes(attributes)
|
11
|
-
end
|
12
|
-
|
13
9
|
private
|
10
|
+
def _assign_attributes(attributes)
|
11
|
+
multi_parameter_attributes = nested_parameter_attributes = nil
|
14
12
|
|
15
|
-
|
16
|
-
|
17
|
-
nested_parameter_attributes = {}
|
13
|
+
attributes.each do |k, v|
|
14
|
+
key = k.to_s
|
18
15
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
16
|
+
if key.include?("(")
|
17
|
+
(multi_parameter_attributes ||= {})[key] = v
|
18
|
+
elsif v.is_a?(Hash)
|
19
|
+
(nested_parameter_attributes ||= {})[key] = v
|
20
|
+
else
|
21
|
+
_assign_attribute(key, v)
|
22
|
+
end
|
24
23
|
end
|
25
|
-
end
|
26
|
-
super(attributes)
|
27
24
|
|
28
|
-
|
29
|
-
|
30
|
-
|
25
|
+
assign_nested_parameter_attributes(nested_parameter_attributes) if nested_parameter_attributes
|
26
|
+
assign_multiparameter_attributes(multi_parameter_attributes) if multi_parameter_attributes
|
27
|
+
end
|
31
28
|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
29
|
+
# Assign any deferred nested attributes after the base attributes have been set.
|
30
|
+
def assign_nested_parameter_attributes(pairs)
|
31
|
+
pairs.each { |k, v| _assign_attribute(k, v) }
|
32
|
+
end
|
36
33
|
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
34
|
+
# Instantiates objects for all attribute classes that needs more than one constructor parameter. This is done
|
35
|
+
# by calling new on the column type or aggregation type (through composed_of) object with these parameters.
|
36
|
+
# So having the pairs written_on(1) = "2004", written_on(2) = "6", written_on(3) = "24", will instantiate
|
37
|
+
# written_on (a date type) with Date.new("2004", "6", "24"). You can also specify a typecast character in the
|
38
|
+
# parentheses to have the parameters typecasted before they're used in the constructor. Use i for Integer and
|
39
|
+
# f for Float. If all the values for a given attribute are empty, the attribute will be set to +nil+.
|
40
|
+
def assign_multiparameter_attributes(pairs)
|
41
|
+
execute_callstack_for_multiparameter_attributes(
|
42
|
+
extract_callstack_for_multiparameter_attributes(pairs)
|
43
|
+
)
|
44
|
+
end
|
48
45
|
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
begin
|
46
|
+
def execute_callstack_for_multiparameter_attributes(callstack)
|
47
|
+
errors = []
|
48
|
+
callstack.each do |name, values_with_empty_parameters|
|
53
49
|
if values_with_empty_parameters.each_value.all?(&:nil?)
|
54
50
|
values = nil
|
55
51
|
else
|
@@ -59,33 +55,32 @@ module ActiveRecord
|
|
59
55
|
rescue => ex
|
60
56
|
errors << AttributeAssignmentError.new("error on assignment #{values_with_empty_parameters.values.inspect} to #{name} (#{ex.message})", ex, name)
|
61
57
|
end
|
58
|
+
unless errors.empty?
|
59
|
+
error_descriptions = errors.map(&:message).join(",")
|
60
|
+
raise MultiparameterAssignmentErrors.new(errors), "#{errors.size} error(s) on assignment of multiparameter attributes [#{error_descriptions}]"
|
61
|
+
end
|
62
62
|
end
|
63
|
-
unless errors.empty?
|
64
|
-
error_descriptions = errors.map(&:message).join(",")
|
65
|
-
raise MultiparameterAssignmentErrors.new(errors), "#{errors.size} error(s) on assignment of multiparameter attributes [#{error_descriptions}]"
|
66
|
-
end
|
67
|
-
end
|
68
63
|
|
69
|
-
|
70
|
-
|
64
|
+
def extract_callstack_for_multiparameter_attributes(pairs)
|
65
|
+
attributes = {}
|
71
66
|
|
72
|
-
|
73
|
-
|
74
|
-
|
67
|
+
pairs.each do |(multiparameter_name, value)|
|
68
|
+
attribute_name = multiparameter_name.split("(").first
|
69
|
+
attributes[attribute_name] ||= {}
|
75
70
|
|
76
|
-
|
77
|
-
|
78
|
-
|
71
|
+
parameter_value = value.empty? ? nil : type_cast_attribute_value(multiparameter_name, value)
|
72
|
+
attributes[attribute_name][find_parameter_position(multiparameter_name)] ||= parameter_value
|
73
|
+
end
|
79
74
|
|
80
|
-
|
81
|
-
|
75
|
+
attributes
|
76
|
+
end
|
82
77
|
|
83
|
-
|
84
|
-
|
85
|
-
|
78
|
+
def type_cast_attribute_value(multiparameter_name, value)
|
79
|
+
multiparameter_name =~ /\([0-9]*([if])\)/ ? value.send("to_" + $1) : value
|
80
|
+
end
|
86
81
|
|
87
|
-
|
88
|
-
|
89
|
-
|
82
|
+
def find_parameter_position(multiparameter_name)
|
83
|
+
multiparameter_name.scan(/\(([0-9]*).*\)/).first.first.to_i
|
84
|
+
end
|
90
85
|
end
|
91
86
|
end
|
@@ -1,7 +1,7 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
require
|
4
|
-
require
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "mutex_m"
|
4
|
+
require "active_support/core_ext/enumerable"
|
5
5
|
|
6
6
|
module ActiveRecord
|
7
7
|
# = Active Record Attribute Methods
|
@@ -19,22 +19,24 @@ module ActiveRecord
|
|
19
19
|
include TimeZoneConversion
|
20
20
|
include Dirty
|
21
21
|
include Serialization
|
22
|
-
|
23
|
-
delegate :column_for_attribute, to: :class
|
24
22
|
end
|
25
23
|
|
26
|
-
|
27
|
-
def self.set_name_cache(name, value)
|
28
|
-
const_name = "ATTR_#{name}"
|
29
|
-
unless const_defined? const_name
|
30
|
-
const_set const_name, value.dup.freeze
|
31
|
-
end
|
32
|
-
end
|
33
|
-
}
|
24
|
+
RESTRICTED_CLASS_METHODS = %w(private public protected allocate new name parent superclass)
|
34
25
|
|
35
|
-
|
26
|
+
class GeneratedAttributeMethods < Module #:nodoc:
|
27
|
+
include Mutex_m
|
28
|
+
end
|
36
29
|
|
37
|
-
class
|
30
|
+
class << self
|
31
|
+
def dangerous_attribute_methods # :nodoc:
|
32
|
+
@dangerous_attribute_methods ||= (
|
33
|
+
Base.instance_methods +
|
34
|
+
Base.private_instance_methods -
|
35
|
+
Base.superclass.instance_methods -
|
36
|
+
Base.superclass.private_instance_methods
|
37
|
+
).map { |m| -m.to_s }.to_set.freeze
|
38
|
+
end
|
39
|
+
end
|
38
40
|
|
39
41
|
module ClassMethods
|
40
42
|
def inherited(child_class) #:nodoc:
|
@@ -43,7 +45,8 @@ module ActiveRecord
|
|
43
45
|
end
|
44
46
|
|
45
47
|
def initialize_generated_modules # :nodoc:
|
46
|
-
@generated_attribute_methods = GeneratedAttributeMethods.new
|
48
|
+
@generated_attribute_methods = const_set(:GeneratedAttributeMethods, GeneratedAttributeMethods.new)
|
49
|
+
private_constant :GeneratedAttributeMethods
|
47
50
|
@attribute_methods_generated = false
|
48
51
|
include @generated_attribute_methods
|
49
52
|
|
@@ -58,11 +61,10 @@ module ActiveRecord
|
|
58
61
|
# attribute methods.
|
59
62
|
generated_attribute_methods.synchronize do
|
60
63
|
return false if @attribute_methods_generated
|
61
|
-
superclass.define_attribute_methods unless
|
64
|
+
superclass.define_attribute_methods unless base_class?
|
62
65
|
super(attribute_names)
|
63
66
|
@attribute_methods_generated = true
|
64
67
|
end
|
65
|
-
true
|
66
68
|
end
|
67
69
|
|
68
70
|
def undefine_attribute_methods # :nodoc:
|
@@ -105,7 +107,7 @@ module ActiveRecord
|
|
105
107
|
# A method name is 'dangerous' if it is already (re)defined by Active Record, but
|
106
108
|
# not by any ancestors. (So 'puts' is not dangerous but 'save' is.)
|
107
109
|
def dangerous_attribute_method?(name) # :nodoc:
|
108
|
-
|
110
|
+
::ActiveRecord::AttributeMethods.dangerous_attribute_methods.include?(name.to_s)
|
109
111
|
end
|
110
112
|
|
111
113
|
def method_defined_within?(name, klass, superklass = klass.superclass) # :nodoc:
|
@@ -123,13 +125,11 @@ module ActiveRecord
|
|
123
125
|
# A class method is 'dangerous' if it is already (re)defined by Active Record, but
|
124
126
|
# not by any ancestors. (So 'puts' is not dangerous but 'new' is.)
|
125
127
|
def dangerous_class_method?(method_name)
|
126
|
-
|
127
|
-
end
|
128
|
+
return true if RESTRICTED_CLASS_METHODS.include?(method_name.to_s)
|
128
129
|
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
klass.method(name).owner != superklass.method(name).owner
|
130
|
+
if Base.respond_to?(method_name, true)
|
131
|
+
if Object.respond_to?(method_name, true)
|
132
|
+
Base.method(method_name).owner != Object.method(method_name).owner
|
133
133
|
else
|
134
134
|
true
|
135
135
|
end
|
@@ -148,7 +148,7 @@ module ActiveRecord
|
|
148
148
|
# Person.attribute_method?(:age=) # => true
|
149
149
|
# Person.attribute_method?(:nothing) # => false
|
150
150
|
def attribute_method?(attribute)
|
151
|
-
super || (table_exists? && column_names.include?(attribute.to_s.
|
151
|
+
super || (table_exists? && column_names.include?(attribute.to_s.delete_suffix("=")))
|
152
152
|
end
|
153
153
|
|
154
154
|
# Returns an array of column names as strings if it's not an abstract class and
|
@@ -161,42 +161,30 @@ module ActiveRecord
|
|
161
161
|
# # => ["id", "created_at", "updated_at", "name", "age"]
|
162
162
|
def attribute_names
|
163
163
|
@attribute_names ||= if !abstract_class? && table_exists?
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
164
|
+
attribute_types.keys
|
165
|
+
else
|
166
|
+
[]
|
167
|
+
end.freeze
|
168
168
|
end
|
169
169
|
|
170
170
|
# Returns true if the given attribute exists, otherwise false.
|
171
171
|
#
|
172
172
|
# class Person < ActiveRecord::Base
|
173
|
+
# alias_attribute :new_name, :name
|
173
174
|
# end
|
174
175
|
#
|
175
|
-
# Person.has_attribute?('name')
|
176
|
-
# Person.has_attribute?(
|
177
|
-
# Person.has_attribute?(:
|
176
|
+
# Person.has_attribute?('name') # => true
|
177
|
+
# Person.has_attribute?('new_name') # => true
|
178
|
+
# Person.has_attribute?(:age) # => true
|
179
|
+
# Person.has_attribute?(:nothing) # => false
|
178
180
|
def has_attribute?(attr_name)
|
179
|
-
|
181
|
+
attr_name = attr_name.to_s
|
182
|
+
attr_name = attribute_aliases[attr_name] || attr_name
|
183
|
+
attribute_types.key?(attr_name)
|
180
184
|
end
|
181
185
|
|
182
|
-
|
183
|
-
|
184
|
-
# named attribute does not exist.
|
185
|
-
#
|
186
|
-
# class Person < ActiveRecord::Base
|
187
|
-
# end
|
188
|
-
#
|
189
|
-
# person = Person.new
|
190
|
-
# person.column_for_attribute(:name) # the result depends on the ConnectionAdapter
|
191
|
-
# # => #<ActiveRecord::ConnectionAdapters::Column:0x007ff4ab083980 @name="name", @sql_type="varchar(255)", @null=true, ...>
|
192
|
-
#
|
193
|
-
# person.column_for_attribute(:nothing)
|
194
|
-
# # => #<ActiveRecord::ConnectionAdapters::NullColumn:0xXXX @name=nil, @sql_type=nil, @cast_type=#<Type::Value>, ...>
|
195
|
-
def column_for_attribute(name)
|
196
|
-
name = name.to_s
|
197
|
-
columns_hash.fetch(name) do
|
198
|
-
ConnectionAdapters::NullColumn.new(name)
|
199
|
-
end
|
186
|
+
def _has_attribute?(attr_name) # :nodoc:
|
187
|
+
attribute_types.key?(attr_name)
|
200
188
|
end
|
201
189
|
end
|
202
190
|
|
@@ -209,47 +197,48 @@ module ActiveRecord
|
|
209
197
|
# end
|
210
198
|
#
|
211
199
|
# person = Person.new
|
212
|
-
# person.respond_to(:name) # => true
|
213
|
-
# person.respond_to(:name=) # => true
|
214
|
-
# person.respond_to(:name?) # => true
|
215
|
-
# person.respond_to('age') # => true
|
216
|
-
# person.respond_to('age=') # => true
|
217
|
-
# person.respond_to('age?') # => true
|
218
|
-
# person.respond_to(:nothing) # => false
|
200
|
+
# person.respond_to?(:name) # => true
|
201
|
+
# person.respond_to?(:name=) # => true
|
202
|
+
# person.respond_to?(:name?) # => true
|
203
|
+
# person.respond_to?('age') # => true
|
204
|
+
# person.respond_to?('age=') # => true
|
205
|
+
# person.respond_to?('age?') # => true
|
206
|
+
# person.respond_to?(:nothing) # => false
|
219
207
|
def respond_to?(name, include_private = false)
|
220
208
|
return false unless super
|
221
209
|
|
222
|
-
case name
|
223
|
-
when :to_partial_path
|
224
|
-
name = "to_partial_path".freeze
|
225
|
-
when :to_model
|
226
|
-
name = "to_model".freeze
|
227
|
-
else
|
228
|
-
name = name.to_s
|
229
|
-
end
|
230
|
-
|
231
210
|
# If the result is true then check for the select case.
|
232
211
|
# For queries selecting a subset of columns, return false for unselected columns.
|
233
212
|
# We check defined?(@attributes) not to issue warnings if called on objects that
|
234
213
|
# have been allocated but not yet initialized.
|
235
|
-
if defined?(@attributes)
|
236
|
-
|
214
|
+
if defined?(@attributes)
|
215
|
+
if name = self.class.symbol_column_to_string(name.to_sym)
|
216
|
+
return _has_attribute?(name)
|
217
|
+
end
|
237
218
|
end
|
238
219
|
|
239
|
-
|
220
|
+
true
|
240
221
|
end
|
241
222
|
|
242
223
|
# Returns +true+ if the given attribute is in the attributes hash, otherwise +false+.
|
243
224
|
#
|
244
225
|
# class Person < ActiveRecord::Base
|
226
|
+
# alias_attribute :new_name, :name
|
245
227
|
# end
|
246
228
|
#
|
247
229
|
# person = Person.new
|
248
|
-
# person.has_attribute?(:name)
|
249
|
-
# person.has_attribute?(
|
250
|
-
# person.has_attribute?(
|
230
|
+
# person.has_attribute?(:name) # => true
|
231
|
+
# person.has_attribute?(:new_name) # => true
|
232
|
+
# person.has_attribute?('age') # => true
|
233
|
+
# person.has_attribute?(:nothing) # => false
|
251
234
|
def has_attribute?(attr_name)
|
252
|
-
|
235
|
+
attr_name = attr_name.to_s
|
236
|
+
attr_name = self.class.attribute_aliases[attr_name] || attr_name
|
237
|
+
@attributes.key?(attr_name)
|
238
|
+
end
|
239
|
+
|
240
|
+
def _has_attribute?(attr_name) # :nodoc:
|
241
|
+
@attributes.key?(attr_name)
|
253
242
|
end
|
254
243
|
|
255
244
|
# Returns an array of names for the attributes available on this object.
|
@@ -293,15 +282,10 @@ module ActiveRecord
|
|
293
282
|
# person.attribute_for_inspect(:tag_ids)
|
294
283
|
# # => "[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]"
|
295
284
|
def attribute_for_inspect(attr_name)
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
elsif value.is_a?(Date) || value.is_a?(Time)
|
301
|
-
%("#{value.to_s(:db)}")
|
302
|
-
else
|
303
|
-
value.inspect
|
304
|
-
end
|
285
|
+
attr_name = attr_name.to_s
|
286
|
+
attr_name = self.class.attribute_aliases[attr_name] || attr_name
|
287
|
+
value = _read_attribute(attr_name)
|
288
|
+
format_for_inspect(attr_name, value)
|
305
289
|
end
|
306
290
|
|
307
291
|
# Returns +true+ if the specified +attribute+ has been set by the user or by a
|
@@ -319,8 +303,10 @@ module ActiveRecord
|
|
319
303
|
# task.is_done = true
|
320
304
|
# task.attribute_present?(:title) # => true
|
321
305
|
# task.attribute_present?(:is_done) # => true
|
322
|
-
def attribute_present?(
|
323
|
-
|
306
|
+
def attribute_present?(attr_name)
|
307
|
+
attr_name = attr_name.to_s
|
308
|
+
attr_name = self.class.attribute_aliases[attr_name] || attr_name
|
309
|
+
value = _read_attribute(attr_name)
|
324
310
|
!value.nil? && !(value.respond_to?(:empty?) && value.empty?)
|
325
311
|
end
|
326
312
|
|
@@ -330,8 +316,6 @@ module ActiveRecord
|
|
330
316
|
#
|
331
317
|
# Note: +:id+ is always present.
|
332
318
|
#
|
333
|
-
# Alias for the #read_attribute method.
|
334
|
-
#
|
335
319
|
# class Person < ActiveRecord::Base
|
336
320
|
# belongs_to :organization
|
337
321
|
# end
|
@@ -394,67 +378,53 @@ module ActiveRecord
|
|
394
378
|
@attributes.accessed
|
395
379
|
end
|
396
380
|
|
397
|
-
protected
|
398
|
-
|
399
|
-
def clone_attribute_value(reader_method, attribute_name) # :nodoc:
|
400
|
-
value = send(reader_method, attribute_name)
|
401
|
-
value.duplicable? ? value.clone : value
|
402
|
-
rescue TypeError, NoMethodError
|
403
|
-
value
|
404
|
-
end
|
405
|
-
|
406
|
-
def arel_attributes_with_values_for_create(attribute_names) # :nodoc:
|
407
|
-
arel_attributes_with_values(attributes_for_create(attribute_names))
|
408
|
-
end
|
409
|
-
|
410
|
-
def arel_attributes_with_values_for_update(attribute_names) # :nodoc:
|
411
|
-
arel_attributes_with_values(attributes_for_update(attribute_names))
|
412
|
-
end
|
413
|
-
|
414
|
-
def attribute_method?(attr_name) # :nodoc:
|
415
|
-
# We check defined? because Syck calls respond_to? before actually calling initialize.
|
416
|
-
defined?(@attributes) && @attributes.key?(attr_name)
|
417
|
-
end
|
418
|
-
|
419
381
|
private
|
382
|
+
def attribute_method?(attr_name)
|
383
|
+
# We check defined? because Syck calls respond_to? before actually calling initialize.
|
384
|
+
defined?(@attributes) && @attributes.key?(attr_name)
|
385
|
+
end
|
420
386
|
|
421
|
-
|
422
|
-
|
423
|
-
|
424
|
-
|
425
|
-
arel_table = self.class.arel_table
|
426
|
-
|
427
|
-
attribute_names.each do |name|
|
428
|
-
attrs[arel_table[name]] = typecasted_attribute_value(name)
|
387
|
+
def attributes_with_values(attribute_names)
|
388
|
+
attribute_names.index_with do |name|
|
389
|
+
_read_attribute(name)
|
390
|
+
end
|
429
391
|
end
|
430
|
-
attrs
|
431
|
-
end
|
432
392
|
|
433
|
-
|
434
|
-
|
435
|
-
|
436
|
-
|
393
|
+
# Filters the primary keys and readonly attributes from the attribute names.
|
394
|
+
def attributes_for_update(attribute_names)
|
395
|
+
attribute_names &= self.class.column_names
|
396
|
+
attribute_names.delete_if do |name|
|
397
|
+
self.class.readonly_attribute?(name)
|
398
|
+
end
|
437
399
|
end
|
438
|
-
end
|
439
400
|
|
440
|
-
|
441
|
-
|
442
|
-
|
443
|
-
|
444
|
-
|
401
|
+
# Filters out the primary keys, from the attribute names, when the primary
|
402
|
+
# key is to be generated (e.g. the id attribute has no value).
|
403
|
+
def attributes_for_create(attribute_names)
|
404
|
+
attribute_names &= self.class.column_names
|
405
|
+
attribute_names.delete_if do |name|
|
406
|
+
pk_attribute?(name) && id.nil?
|
407
|
+
end
|
445
408
|
end
|
446
|
-
end
|
447
409
|
|
448
|
-
|
449
|
-
|
450
|
-
|
410
|
+
def format_for_inspect(name, value)
|
411
|
+
if value.nil?
|
412
|
+
value.inspect
|
413
|
+
else
|
414
|
+
inspected_value = if value.is_a?(String) && value.length > 50
|
415
|
+
"#{value[0, 50]}...".inspect
|
416
|
+
elsif value.is_a?(Date) || value.is_a?(Time)
|
417
|
+
%("#{value.to_s(:inspect)}")
|
418
|
+
else
|
419
|
+
value.inspect
|
420
|
+
end
|
451
421
|
|
452
|
-
|
453
|
-
|
454
|
-
|
422
|
+
inspection_filter.filter_param(name, inspected_value)
|
423
|
+
end
|
424
|
+
end
|
455
425
|
|
456
|
-
|
457
|
-
|
458
|
-
|
426
|
+
def pk_attribute?(name)
|
427
|
+
name == @primary_key
|
428
|
+
end
|
459
429
|
end
|
460
430
|
end
|