activerecord 3.2.22.5 → 5.2.8
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 +657 -621
- data/MIT-LICENSE +2 -2
- data/README.rdoc +41 -46
- data/examples/performance.rb +55 -42
- data/examples/simple.rb +6 -5
- data/lib/active_record/aggregations.rb +264 -236
- data/lib/active_record/association_relation.rb +40 -0
- data/lib/active_record/associations/alias_tracker.rb +47 -42
- data/lib/active_record/associations/association.rb +127 -75
- data/lib/active_record/associations/association_scope.rb +126 -92
- data/lib/active_record/associations/belongs_to_association.rb +78 -27
- data/lib/active_record/associations/belongs_to_polymorphic_association.rb +9 -4
- data/lib/active_record/associations/builder/association.rb +117 -32
- data/lib/active_record/associations/builder/belongs_to.rb +135 -60
- data/lib/active_record/associations/builder/collection_association.rb +61 -54
- data/lib/active_record/associations/builder/has_and_belongs_to_many.rb +120 -42
- data/lib/active_record/associations/builder/has_many.rb +10 -64
- data/lib/active_record/associations/builder/has_one.rb +19 -51
- data/lib/active_record/associations/builder/singular_association.rb +28 -18
- data/lib/active_record/associations/collection_association.rb +226 -293
- data/lib/active_record/associations/collection_proxy.rb +1067 -69
- data/lib/active_record/associations/foreign_association.rb +13 -0
- data/lib/active_record/associations/has_many_association.rb +83 -47
- data/lib/active_record/associations/has_many_through_association.rb +98 -65
- data/lib/active_record/associations/has_one_association.rb +57 -20
- data/lib/active_record/associations/has_one_through_association.rb +18 -9
- data/lib/active_record/associations/join_dependency/join_association.rb +48 -126
- data/lib/active_record/associations/join_dependency/join_base.rb +11 -12
- data/lib/active_record/associations/join_dependency/join_part.rb +35 -42
- data/lib/active_record/associations/join_dependency.rb +212 -164
- data/lib/active_record/associations/preloader/association.rb +95 -89
- data/lib/active_record/associations/preloader/through_association.rb +84 -44
- data/lib/active_record/associations/preloader.rb +123 -111
- data/lib/active_record/associations/singular_association.rb +33 -24
- data/lib/active_record/associations/through_association.rb +60 -26
- data/lib/active_record/associations.rb +1759 -1506
- data/lib/active_record/attribute_assignment.rb +60 -193
- data/lib/active_record/attribute_decorators.rb +90 -0
- data/lib/active_record/attribute_methods/before_type_cast.rb +55 -8
- data/lib/active_record/attribute_methods/dirty.rb +113 -74
- data/lib/active_record/attribute_methods/primary_key.rb +106 -77
- data/lib/active_record/attribute_methods/query.rb +8 -5
- data/lib/active_record/attribute_methods/read.rb +63 -114
- data/lib/active_record/attribute_methods/serialization.rb +60 -90
- data/lib/active_record/attribute_methods/time_zone_conversion.rb +69 -43
- data/lib/active_record/attribute_methods/write.rb +43 -45
- data/lib/active_record/attribute_methods.rb +366 -149
- data/lib/active_record/attributes.rb +266 -0
- data/lib/active_record/autosave_association.rb +312 -225
- data/lib/active_record/base.rb +114 -505
- data/lib/active_record/callbacks.rb +145 -67
- data/lib/active_record/coders/json.rb +15 -0
- data/lib/active_record/coders/yaml_column.rb +32 -23
- data/lib/active_record/collection_cache_key.rb +53 -0
- data/lib/active_record/connection_adapters/abstract/connection_pool.rb +883 -284
- data/lib/active_record/connection_adapters/abstract/database_limits.rb +16 -2
- data/lib/active_record/connection_adapters/abstract/database_statements.rb +350 -200
- data/lib/active_record/connection_adapters/abstract/query_cache.rb +82 -27
- data/lib/active_record/connection_adapters/abstract/quoting.rb +150 -65
- data/lib/active_record/connection_adapters/abstract/savepoints.rb +23 -0
- data/lib/active_record/connection_adapters/abstract/schema_creation.rb +146 -0
- data/lib/active_record/connection_adapters/abstract/schema_definitions.rb +477 -284
- data/lib/active_record/connection_adapters/abstract/schema_dumper.rb +95 -0
- data/lib/active_record/connection_adapters/abstract/schema_statements.rb +1100 -310
- data/lib/active_record/connection_adapters/abstract/transaction.rb +283 -0
- data/lib/active_record/connection_adapters/abstract_adapter.rb +450 -118
- data/lib/active_record/connection_adapters/abstract_mysql_adapter.rb +657 -446
- data/lib/active_record/connection_adapters/column.rb +50 -255
- data/lib/active_record/connection_adapters/connection_specification.rb +287 -0
- data/lib/active_record/connection_adapters/determine_if_preparable_visitor.rb +33 -0
- data/lib/active_record/connection_adapters/mysql/column.rb +27 -0
- data/lib/active_record/connection_adapters/mysql/database_statements.rb +140 -0
- data/lib/active_record/connection_adapters/mysql/explain_pretty_printer.rb +72 -0
- data/lib/active_record/connection_adapters/mysql/quoting.rb +44 -0
- data/lib/active_record/connection_adapters/mysql/schema_creation.rb +73 -0
- data/lib/active_record/connection_adapters/mysql/schema_definitions.rb +87 -0
- data/lib/active_record/connection_adapters/mysql/schema_dumper.rb +80 -0
- data/lib/active_record/connection_adapters/mysql/schema_statements.rb +148 -0
- data/lib/active_record/connection_adapters/mysql/type_metadata.rb +35 -0
- data/lib/active_record/connection_adapters/mysql2_adapter.rb +59 -210
- data/lib/active_record/connection_adapters/postgresql/column.rb +44 -0
- data/lib/active_record/connection_adapters/postgresql/database_statements.rb +163 -0
- data/lib/active_record/connection_adapters/postgresql/explain_pretty_printer.rb +44 -0
- data/lib/active_record/connection_adapters/postgresql/oid/array.rb +92 -0
- data/lib/active_record/connection_adapters/postgresql/oid/bit.rb +56 -0
- data/lib/active_record/connection_adapters/postgresql/oid/bit_varying.rb +15 -0
- data/lib/active_record/connection_adapters/postgresql/oid/bytea.rb +17 -0
- data/lib/active_record/connection_adapters/postgresql/oid/cidr.rb +50 -0
- data/lib/active_record/connection_adapters/postgresql/oid/date.rb +23 -0
- data/lib/active_record/connection_adapters/postgresql/oid/date_time.rb +23 -0
- data/lib/active_record/connection_adapters/postgresql/oid/decimal.rb +15 -0
- data/lib/active_record/connection_adapters/postgresql/oid/enum.rb +21 -0
- data/lib/active_record/connection_adapters/postgresql/oid/hstore.rb +71 -0
- data/lib/active_record/connection_adapters/postgresql/oid/inet.rb +15 -0
- data/lib/active_record/connection_adapters/postgresql/oid/jsonb.rb +15 -0
- data/lib/active_record/connection_adapters/postgresql/oid/legacy_point.rb +45 -0
- data/lib/active_record/connection_adapters/postgresql/oid/money.rb +41 -0
- data/lib/active_record/connection_adapters/postgresql/oid/oid.rb +15 -0
- data/lib/active_record/connection_adapters/postgresql/oid/point.rb +65 -0
- data/lib/active_record/connection_adapters/postgresql/oid/range.rb +97 -0
- data/lib/active_record/connection_adapters/postgresql/oid/specialized_string.rb +18 -0
- data/lib/active_record/connection_adapters/postgresql/oid/type_map_initializer.rb +111 -0
- data/lib/active_record/connection_adapters/postgresql/oid/uuid.rb +23 -0
- data/lib/active_record/connection_adapters/postgresql/oid/vector.rb +28 -0
- data/lib/active_record/connection_adapters/postgresql/oid/xml.rb +30 -0
- data/lib/active_record/connection_adapters/postgresql/oid.rb +34 -0
- data/lib/active_record/connection_adapters/postgresql/quoting.rb +168 -0
- data/lib/active_record/connection_adapters/postgresql/referential_integrity.rb +43 -0
- data/lib/active_record/connection_adapters/postgresql/schema_creation.rb +65 -0
- data/lib/active_record/connection_adapters/postgresql/schema_definitions.rb +206 -0
- data/lib/active_record/connection_adapters/postgresql/schema_dumper.rb +50 -0
- data/lib/active_record/connection_adapters/postgresql/schema_statements.rb +774 -0
- data/lib/active_record/connection_adapters/postgresql/type_metadata.rb +39 -0
- data/lib/active_record/connection_adapters/postgresql/utils.rb +81 -0
- data/lib/active_record/connection_adapters/postgresql_adapter.rb +620 -1080
- data/lib/active_record/connection_adapters/schema_cache.rb +85 -36
- data/lib/active_record/connection_adapters/sql_type_metadata.rb +34 -0
- data/lib/active_record/connection_adapters/sqlite3/explain_pretty_printer.rb +21 -0
- data/lib/active_record/connection_adapters/sqlite3/quoting.rb +67 -0
- data/lib/active_record/connection_adapters/sqlite3/schema_creation.rb +17 -0
- data/lib/active_record/connection_adapters/sqlite3/schema_definitions.rb +19 -0
- data/lib/active_record/connection_adapters/sqlite3/schema_dumper.rb +18 -0
- data/lib/active_record/connection_adapters/sqlite3/schema_statements.rb +106 -0
- data/lib/active_record/connection_adapters/sqlite3_adapter.rb +545 -27
- data/lib/active_record/connection_adapters/statement_pool.rb +34 -13
- data/lib/active_record/connection_handling.rb +145 -0
- data/lib/active_record/core.rb +559 -0
- data/lib/active_record/counter_cache.rb +200 -105
- data/lib/active_record/define_callbacks.rb +22 -0
- data/lib/active_record/dynamic_matchers.rb +107 -69
- data/lib/active_record/enum.rb +244 -0
- data/lib/active_record/errors.rb +245 -60
- data/lib/active_record/explain.rb +35 -71
- data/lib/active_record/explain_registry.rb +32 -0
- data/lib/active_record/explain_subscriber.rb +18 -9
- data/lib/active_record/fixture_set/file.rb +82 -0
- data/lib/active_record/fixtures.rb +418 -275
- data/lib/active_record/gem_version.rb +17 -0
- data/lib/active_record/inheritance.rb +209 -100
- data/lib/active_record/integration.rb +116 -21
- data/lib/active_record/internal_metadata.rb +45 -0
- data/lib/active_record/legacy_yaml_adapter.rb +48 -0
- data/lib/active_record/locale/en.yml +9 -1
- data/lib/active_record/locking/optimistic.rb +107 -94
- data/lib/active_record/locking/pessimistic.rb +20 -8
- data/lib/active_record/log_subscriber.rb +99 -34
- data/lib/active_record/migration/command_recorder.rb +199 -64
- data/lib/active_record/migration/compatibility.rb +217 -0
- data/lib/active_record/migration/join_table.rb +17 -0
- data/lib/active_record/migration.rb +893 -296
- data/lib/active_record/model_schema.rb +328 -175
- data/lib/active_record/nested_attributes.rb +338 -242
- data/lib/active_record/no_touching.rb +58 -0
- data/lib/active_record/null_relation.rb +68 -0
- data/lib/active_record/persistence.rb +557 -170
- data/lib/active_record/query_cache.rb +14 -43
- data/lib/active_record/querying.rb +36 -24
- data/lib/active_record/railtie.rb +147 -52
- data/lib/active_record/railties/console_sandbox.rb +5 -4
- data/lib/active_record/railties/controller_runtime.rb +13 -6
- data/lib/active_record/railties/databases.rake +206 -488
- data/lib/active_record/readonly_attributes.rb +4 -6
- data/lib/active_record/reflection.rb +734 -228
- data/lib/active_record/relation/batches/batch_enumerator.rb +69 -0
- data/lib/active_record/relation/batches.rb +249 -52
- data/lib/active_record/relation/calculations.rb +330 -284
- data/lib/active_record/relation/delegation.rb +135 -37
- data/lib/active_record/relation/finder_methods.rb +450 -287
- data/lib/active_record/relation/from_clause.rb +26 -0
- data/lib/active_record/relation/merger.rb +193 -0
- data/lib/active_record/relation/predicate_builder/array_handler.rb +48 -0
- data/lib/active_record/relation/predicate_builder/association_query_value.rb +46 -0
- data/lib/active_record/relation/predicate_builder/base_handler.rb +19 -0
- data/lib/active_record/relation/predicate_builder/basic_object_handler.rb +20 -0
- data/lib/active_record/relation/predicate_builder/polymorphic_array_value.rb +56 -0
- data/lib/active_record/relation/predicate_builder/range_handler.rb +42 -0
- data/lib/active_record/relation/predicate_builder/relation_handler.rb +19 -0
- data/lib/active_record/relation/predicate_builder.rb +132 -43
- data/lib/active_record/relation/query_attribute.rb +45 -0
- data/lib/active_record/relation/query_methods.rb +1037 -221
- data/lib/active_record/relation/record_fetch_warning.rb +51 -0
- data/lib/active_record/relation/spawn_methods.rb +48 -151
- data/lib/active_record/relation/where_clause.rb +186 -0
- data/lib/active_record/relation/where_clause_factory.rb +34 -0
- data/lib/active_record/relation.rb +451 -359
- data/lib/active_record/result.rb +129 -20
- data/lib/active_record/runtime_registry.rb +24 -0
- data/lib/active_record/sanitization.rb +164 -136
- data/lib/active_record/schema.rb +31 -19
- data/lib/active_record/schema_dumper.rb +154 -107
- data/lib/active_record/schema_migration.rb +56 -0
- data/lib/active_record/scoping/default.rb +108 -98
- data/lib/active_record/scoping/named.rb +125 -112
- data/lib/active_record/scoping.rb +77 -123
- data/lib/active_record/secure_token.rb +40 -0
- data/lib/active_record/serialization.rb +10 -6
- data/lib/active_record/statement_cache.rb +121 -0
- data/lib/active_record/store.rb +175 -16
- data/lib/active_record/suppressor.rb +61 -0
- data/lib/active_record/table_metadata.rb +82 -0
- data/lib/active_record/tasks/database_tasks.rb +337 -0
- data/lib/active_record/tasks/mysql_database_tasks.rb +115 -0
- data/lib/active_record/tasks/postgresql_database_tasks.rb +143 -0
- data/lib/active_record/tasks/sqlite_database_tasks.rb +83 -0
- data/lib/active_record/timestamp.rb +80 -41
- data/lib/active_record/touch_later.rb +64 -0
- data/lib/active_record/transactions.rb +240 -119
- data/lib/active_record/translation.rb +2 -0
- data/lib/active_record/type/adapter_specific_registry.rb +136 -0
- data/lib/active_record/type/date.rb +9 -0
- data/lib/active_record/type/date_time.rb +9 -0
- data/lib/active_record/type/decimal_without_scale.rb +15 -0
- data/lib/active_record/type/hash_lookup_type_map.rb +25 -0
- data/lib/active_record/type/internal/timezone.rb +17 -0
- data/lib/active_record/type/json.rb +30 -0
- data/lib/active_record/type/serialized.rb +71 -0
- data/lib/active_record/type/text.rb +11 -0
- data/lib/active_record/type/time.rb +21 -0
- data/lib/active_record/type/type_map.rb +62 -0
- data/lib/active_record/type/unsigned_integer.rb +17 -0
- data/lib/active_record/type.rb +79 -0
- data/lib/active_record/type_caster/connection.rb +33 -0
- data/lib/active_record/type_caster/map.rb +23 -0
- data/lib/active_record/type_caster.rb +9 -0
- data/lib/active_record/validations/absence.rb +25 -0
- data/lib/active_record/validations/associated.rb +35 -18
- data/lib/active_record/validations/length.rb +26 -0
- data/lib/active_record/validations/presence.rb +68 -0
- data/lib/active_record/validations/uniqueness.rb +133 -75
- data/lib/active_record/validations.rb +53 -43
- data/lib/active_record/version.rb +7 -7
- data/lib/active_record.rb +89 -57
- data/lib/rails/generators/active_record/application_record/application_record_generator.rb +27 -0
- data/lib/rails/generators/active_record/application_record/templates/application_record.rb.tt +5 -0
- data/lib/rails/generators/active_record/migration/migration_generator.rb +61 -8
- data/lib/rails/generators/active_record/migration/templates/create_table_migration.rb.tt +24 -0
- data/lib/rails/generators/active_record/migration/templates/migration.rb.tt +46 -0
- data/lib/rails/generators/active_record/migration.rb +28 -8
- data/lib/rails/generators/active_record/model/model_generator.rb +23 -22
- data/lib/rails/generators/active_record/model/templates/model.rb.tt +13 -0
- data/lib/rails/generators/active_record/model/templates/{module.rb → module.rb.tt} +1 -1
- data/lib/rails/generators/active_record.rb +10 -16
- metadata +141 -62
- data/examples/associations.png +0 -0
- data/lib/active_record/associations/has_and_belongs_to_many_association.rb +0 -63
- data/lib/active_record/associations/join_helper.rb +0 -55
- data/lib/active_record/associations/preloader/belongs_to.rb +0 -17
- data/lib/active_record/associations/preloader/collection_association.rb +0 -24
- data/lib/active_record/associations/preloader/has_and_belongs_to_many.rb +0 -60
- data/lib/active_record/associations/preloader/has_many.rb +0 -17
- data/lib/active_record/associations/preloader/has_many_through.rb +0 -15
- data/lib/active_record/associations/preloader/has_one.rb +0 -23
- data/lib/active_record/associations/preloader/has_one_through.rb +0 -9
- data/lib/active_record/associations/preloader/singular_association.rb +0 -21
- data/lib/active_record/attribute_methods/deprecated_underscore_read.rb +0 -32
- data/lib/active_record/connection_adapters/abstract/connection_specification.rb +0 -191
- data/lib/active_record/connection_adapters/mysql_adapter.rb +0 -441
- data/lib/active_record/connection_adapters/sqlite_adapter.rb +0 -583
- data/lib/active_record/dynamic_finder_match.rb +0 -68
- data/lib/active_record/dynamic_scope_match.rb +0 -23
- data/lib/active_record/fixtures/file.rb +0 -65
- data/lib/active_record/identity_map.rb +0 -162
- data/lib/active_record/observer.rb +0 -121
- data/lib/active_record/railties/jdbcmysql_error.rb +0 -16
- data/lib/active_record/serializers/xml_serializer.rb +0 -203
- data/lib/active_record/session_store.rb +0 -360
- data/lib/active_record/test_case.rb +0 -73
- data/lib/rails/generators/active_record/migration/templates/migration.rb +0 -34
- data/lib/rails/generators/active_record/model/templates/migration.rb +0 -15
- data/lib/rails/generators/active_record/model/templates/model.rb +0 -12
- data/lib/rails/generators/active_record/observer/observer_generator.rb +0 -15
- data/lib/rails/generators/active_record/observer/templates/observer.rb +0 -4
- data/lib/rails/generators/active_record/session_migration/session_migration_generator.rb +0 -25
- data/lib/rails/generators/active_record/session_migration/templates/migration.rb +0 -12
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: activerecord
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 5.2.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- David Heinemeier Hansson
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-05-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -16,56 +16,42 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - '='
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
19
|
+
version: 5.2.8
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - '='
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version:
|
26
|
+
version: 5.2.8
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: activemodel
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - '='
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version:
|
33
|
+
version: 5.2.8
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - '='
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version:
|
40
|
+
version: 5.2.8
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: arel
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- - "
|
45
|
+
- - ">="
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version:
|
47
|
+
version: '9.0'
|
48
48
|
type: :runtime
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- - "
|
52
|
+
- - ">="
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version:
|
55
|
-
- !ruby/object:Gem::Dependency
|
56
|
-
name: tzinfo
|
57
|
-
requirement: !ruby/object:Gem::Requirement
|
58
|
-
requirements:
|
59
|
-
- - "~>"
|
60
|
-
- !ruby/object:Gem::Version
|
61
|
-
version: 0.3.29
|
62
|
-
type: :runtime
|
63
|
-
prerelease: false
|
64
|
-
version_requirements: !ruby/object:Gem::Requirement
|
65
|
-
requirements:
|
66
|
-
- - "~>"
|
67
|
-
- !ruby/object:Gem::Version
|
68
|
-
version: 0.3.29
|
54
|
+
version: '9.0'
|
69
55
|
description: Databases on Rails. Build a persistent domain model by mapping database
|
70
56
|
tables to Ruby classes. Strong conventions for associations, validations, aggregations,
|
71
57
|
migrations, and testing come baked-in.
|
@@ -78,11 +64,11 @@ files:
|
|
78
64
|
- CHANGELOG.md
|
79
65
|
- MIT-LICENSE
|
80
66
|
- README.rdoc
|
81
|
-
- examples/associations.png
|
82
67
|
- examples/performance.rb
|
83
68
|
- examples/simple.rb
|
84
69
|
- lib/active_record.rb
|
85
70
|
- lib/active_record/aggregations.rb
|
71
|
+
- lib/active_record/association_relation.rb
|
86
72
|
- lib/active_record/associations.rb
|
87
73
|
- lib/active_record/associations/alias_tracker.rb
|
88
74
|
- lib/active_record/associations/association.rb
|
@@ -98,7 +84,7 @@ files:
|
|
98
84
|
- lib/active_record/associations/builder/singular_association.rb
|
99
85
|
- lib/active_record/associations/collection_association.rb
|
100
86
|
- lib/active_record/associations/collection_proxy.rb
|
101
|
-
- lib/active_record/associations/
|
87
|
+
- lib/active_record/associations/foreign_association.rb
|
102
88
|
- lib/active_record/associations/has_many_association.rb
|
103
89
|
- lib/active_record/associations/has_many_through_association.rb
|
104
90
|
- lib/active_record/associations/has_one_association.rb
|
@@ -107,24 +93,15 @@ files:
|
|
107
93
|
- lib/active_record/associations/join_dependency/join_association.rb
|
108
94
|
- lib/active_record/associations/join_dependency/join_base.rb
|
109
95
|
- lib/active_record/associations/join_dependency/join_part.rb
|
110
|
-
- lib/active_record/associations/join_helper.rb
|
111
96
|
- lib/active_record/associations/preloader.rb
|
112
97
|
- lib/active_record/associations/preloader/association.rb
|
113
|
-
- lib/active_record/associations/preloader/belongs_to.rb
|
114
|
-
- lib/active_record/associations/preloader/collection_association.rb
|
115
|
-
- lib/active_record/associations/preloader/has_and_belongs_to_many.rb
|
116
|
-
- lib/active_record/associations/preloader/has_many.rb
|
117
|
-
- lib/active_record/associations/preloader/has_many_through.rb
|
118
|
-
- lib/active_record/associations/preloader/has_one.rb
|
119
|
-
- lib/active_record/associations/preloader/has_one_through.rb
|
120
|
-
- lib/active_record/associations/preloader/singular_association.rb
|
121
98
|
- lib/active_record/associations/preloader/through_association.rb
|
122
99
|
- lib/active_record/associations/singular_association.rb
|
123
100
|
- lib/active_record/associations/through_association.rb
|
124
101
|
- lib/active_record/attribute_assignment.rb
|
102
|
+
- lib/active_record/attribute_decorators.rb
|
125
103
|
- lib/active_record/attribute_methods.rb
|
126
104
|
- lib/active_record/attribute_methods/before_type_cast.rb
|
127
|
-
- lib/active_record/attribute_methods/deprecated_underscore_read.rb
|
128
105
|
- lib/active_record/attribute_methods/dirty.rb
|
129
106
|
- lib/active_record/attribute_methods/primary_key.rb
|
130
107
|
- lib/active_record/attribute_methods/query.rb
|
@@ -132,49 +109,113 @@ files:
|
|
132
109
|
- lib/active_record/attribute_methods/serialization.rb
|
133
110
|
- lib/active_record/attribute_methods/time_zone_conversion.rb
|
134
111
|
- lib/active_record/attribute_methods/write.rb
|
112
|
+
- lib/active_record/attributes.rb
|
135
113
|
- lib/active_record/autosave_association.rb
|
136
114
|
- lib/active_record/base.rb
|
137
115
|
- lib/active_record/callbacks.rb
|
116
|
+
- lib/active_record/coders/json.rb
|
138
117
|
- lib/active_record/coders/yaml_column.rb
|
118
|
+
- lib/active_record/collection_cache_key.rb
|
139
119
|
- lib/active_record/connection_adapters/abstract/connection_pool.rb
|
140
|
-
- lib/active_record/connection_adapters/abstract/connection_specification.rb
|
141
120
|
- lib/active_record/connection_adapters/abstract/database_limits.rb
|
142
121
|
- lib/active_record/connection_adapters/abstract/database_statements.rb
|
143
122
|
- lib/active_record/connection_adapters/abstract/query_cache.rb
|
144
123
|
- lib/active_record/connection_adapters/abstract/quoting.rb
|
124
|
+
- lib/active_record/connection_adapters/abstract/savepoints.rb
|
125
|
+
- lib/active_record/connection_adapters/abstract/schema_creation.rb
|
145
126
|
- lib/active_record/connection_adapters/abstract/schema_definitions.rb
|
127
|
+
- lib/active_record/connection_adapters/abstract/schema_dumper.rb
|
146
128
|
- lib/active_record/connection_adapters/abstract/schema_statements.rb
|
129
|
+
- lib/active_record/connection_adapters/abstract/transaction.rb
|
147
130
|
- lib/active_record/connection_adapters/abstract_adapter.rb
|
148
131
|
- lib/active_record/connection_adapters/abstract_mysql_adapter.rb
|
149
132
|
- lib/active_record/connection_adapters/column.rb
|
133
|
+
- lib/active_record/connection_adapters/connection_specification.rb
|
134
|
+
- lib/active_record/connection_adapters/determine_if_preparable_visitor.rb
|
135
|
+
- lib/active_record/connection_adapters/mysql/column.rb
|
136
|
+
- lib/active_record/connection_adapters/mysql/database_statements.rb
|
137
|
+
- lib/active_record/connection_adapters/mysql/explain_pretty_printer.rb
|
138
|
+
- lib/active_record/connection_adapters/mysql/quoting.rb
|
139
|
+
- lib/active_record/connection_adapters/mysql/schema_creation.rb
|
140
|
+
- lib/active_record/connection_adapters/mysql/schema_definitions.rb
|
141
|
+
- lib/active_record/connection_adapters/mysql/schema_dumper.rb
|
142
|
+
- lib/active_record/connection_adapters/mysql/schema_statements.rb
|
143
|
+
- lib/active_record/connection_adapters/mysql/type_metadata.rb
|
150
144
|
- lib/active_record/connection_adapters/mysql2_adapter.rb
|
151
|
-
- lib/active_record/connection_adapters/
|
145
|
+
- lib/active_record/connection_adapters/postgresql/column.rb
|
146
|
+
- lib/active_record/connection_adapters/postgresql/database_statements.rb
|
147
|
+
- lib/active_record/connection_adapters/postgresql/explain_pretty_printer.rb
|
148
|
+
- lib/active_record/connection_adapters/postgresql/oid.rb
|
149
|
+
- lib/active_record/connection_adapters/postgresql/oid/array.rb
|
150
|
+
- lib/active_record/connection_adapters/postgresql/oid/bit.rb
|
151
|
+
- lib/active_record/connection_adapters/postgresql/oid/bit_varying.rb
|
152
|
+
- lib/active_record/connection_adapters/postgresql/oid/bytea.rb
|
153
|
+
- lib/active_record/connection_adapters/postgresql/oid/cidr.rb
|
154
|
+
- lib/active_record/connection_adapters/postgresql/oid/date.rb
|
155
|
+
- lib/active_record/connection_adapters/postgresql/oid/date_time.rb
|
156
|
+
- lib/active_record/connection_adapters/postgresql/oid/decimal.rb
|
157
|
+
- lib/active_record/connection_adapters/postgresql/oid/enum.rb
|
158
|
+
- lib/active_record/connection_adapters/postgresql/oid/hstore.rb
|
159
|
+
- lib/active_record/connection_adapters/postgresql/oid/inet.rb
|
160
|
+
- lib/active_record/connection_adapters/postgresql/oid/jsonb.rb
|
161
|
+
- lib/active_record/connection_adapters/postgresql/oid/legacy_point.rb
|
162
|
+
- lib/active_record/connection_adapters/postgresql/oid/money.rb
|
163
|
+
- lib/active_record/connection_adapters/postgresql/oid/oid.rb
|
164
|
+
- lib/active_record/connection_adapters/postgresql/oid/point.rb
|
165
|
+
- lib/active_record/connection_adapters/postgresql/oid/range.rb
|
166
|
+
- lib/active_record/connection_adapters/postgresql/oid/specialized_string.rb
|
167
|
+
- lib/active_record/connection_adapters/postgresql/oid/type_map_initializer.rb
|
168
|
+
- lib/active_record/connection_adapters/postgresql/oid/uuid.rb
|
169
|
+
- lib/active_record/connection_adapters/postgresql/oid/vector.rb
|
170
|
+
- lib/active_record/connection_adapters/postgresql/oid/xml.rb
|
171
|
+
- lib/active_record/connection_adapters/postgresql/quoting.rb
|
172
|
+
- lib/active_record/connection_adapters/postgresql/referential_integrity.rb
|
173
|
+
- lib/active_record/connection_adapters/postgresql/schema_creation.rb
|
174
|
+
- lib/active_record/connection_adapters/postgresql/schema_definitions.rb
|
175
|
+
- lib/active_record/connection_adapters/postgresql/schema_dumper.rb
|
176
|
+
- lib/active_record/connection_adapters/postgresql/schema_statements.rb
|
177
|
+
- lib/active_record/connection_adapters/postgresql/type_metadata.rb
|
178
|
+
- lib/active_record/connection_adapters/postgresql/utils.rb
|
152
179
|
- lib/active_record/connection_adapters/postgresql_adapter.rb
|
153
180
|
- lib/active_record/connection_adapters/schema_cache.rb
|
181
|
+
- lib/active_record/connection_adapters/sql_type_metadata.rb
|
182
|
+
- lib/active_record/connection_adapters/sqlite3/explain_pretty_printer.rb
|
183
|
+
- lib/active_record/connection_adapters/sqlite3/quoting.rb
|
184
|
+
- lib/active_record/connection_adapters/sqlite3/schema_creation.rb
|
185
|
+
- lib/active_record/connection_adapters/sqlite3/schema_definitions.rb
|
186
|
+
- lib/active_record/connection_adapters/sqlite3/schema_dumper.rb
|
187
|
+
- lib/active_record/connection_adapters/sqlite3/schema_statements.rb
|
154
188
|
- lib/active_record/connection_adapters/sqlite3_adapter.rb
|
155
|
-
- lib/active_record/connection_adapters/sqlite_adapter.rb
|
156
189
|
- lib/active_record/connection_adapters/statement_pool.rb
|
190
|
+
- lib/active_record/connection_handling.rb
|
191
|
+
- lib/active_record/core.rb
|
157
192
|
- lib/active_record/counter_cache.rb
|
158
|
-
- lib/active_record/
|
193
|
+
- lib/active_record/define_callbacks.rb
|
159
194
|
- lib/active_record/dynamic_matchers.rb
|
160
|
-
- lib/active_record/
|
195
|
+
- lib/active_record/enum.rb
|
161
196
|
- lib/active_record/errors.rb
|
162
197
|
- lib/active_record/explain.rb
|
198
|
+
- lib/active_record/explain_registry.rb
|
163
199
|
- lib/active_record/explain_subscriber.rb
|
200
|
+
- lib/active_record/fixture_set/file.rb
|
164
201
|
- lib/active_record/fixtures.rb
|
165
|
-
- lib/active_record/
|
166
|
-
- lib/active_record/identity_map.rb
|
202
|
+
- lib/active_record/gem_version.rb
|
167
203
|
- lib/active_record/inheritance.rb
|
168
204
|
- lib/active_record/integration.rb
|
205
|
+
- lib/active_record/internal_metadata.rb
|
206
|
+
- lib/active_record/legacy_yaml_adapter.rb
|
169
207
|
- lib/active_record/locale/en.yml
|
170
208
|
- lib/active_record/locking/optimistic.rb
|
171
209
|
- lib/active_record/locking/pessimistic.rb
|
172
210
|
- lib/active_record/log_subscriber.rb
|
173
211
|
- lib/active_record/migration.rb
|
174
212
|
- lib/active_record/migration/command_recorder.rb
|
213
|
+
- lib/active_record/migration/compatibility.rb
|
214
|
+
- lib/active_record/migration/join_table.rb
|
175
215
|
- lib/active_record/model_schema.rb
|
176
216
|
- lib/active_record/nested_attributes.rb
|
177
|
-
- lib/active_record/
|
217
|
+
- lib/active_record/no_touching.rb
|
218
|
+
- lib/active_record/null_relation.rb
|
178
219
|
- lib/active_record/persistence.rb
|
179
220
|
- lib/active_record/query_cache.rb
|
180
221
|
- lib/active_record/querying.rb
|
@@ -182,52 +223,92 @@ files:
|
|
182
223
|
- lib/active_record/railties/console_sandbox.rb
|
183
224
|
- lib/active_record/railties/controller_runtime.rb
|
184
225
|
- lib/active_record/railties/databases.rake
|
185
|
-
- lib/active_record/railties/jdbcmysql_error.rb
|
186
226
|
- lib/active_record/readonly_attributes.rb
|
187
227
|
- lib/active_record/reflection.rb
|
188
228
|
- lib/active_record/relation.rb
|
189
229
|
- lib/active_record/relation/batches.rb
|
230
|
+
- lib/active_record/relation/batches/batch_enumerator.rb
|
190
231
|
- lib/active_record/relation/calculations.rb
|
191
232
|
- lib/active_record/relation/delegation.rb
|
192
233
|
- lib/active_record/relation/finder_methods.rb
|
234
|
+
- lib/active_record/relation/from_clause.rb
|
235
|
+
- lib/active_record/relation/merger.rb
|
193
236
|
- lib/active_record/relation/predicate_builder.rb
|
237
|
+
- lib/active_record/relation/predicate_builder/array_handler.rb
|
238
|
+
- lib/active_record/relation/predicate_builder/association_query_value.rb
|
239
|
+
- lib/active_record/relation/predicate_builder/base_handler.rb
|
240
|
+
- lib/active_record/relation/predicate_builder/basic_object_handler.rb
|
241
|
+
- lib/active_record/relation/predicate_builder/polymorphic_array_value.rb
|
242
|
+
- lib/active_record/relation/predicate_builder/range_handler.rb
|
243
|
+
- lib/active_record/relation/predicate_builder/relation_handler.rb
|
244
|
+
- lib/active_record/relation/query_attribute.rb
|
194
245
|
- lib/active_record/relation/query_methods.rb
|
246
|
+
- lib/active_record/relation/record_fetch_warning.rb
|
195
247
|
- lib/active_record/relation/spawn_methods.rb
|
248
|
+
- lib/active_record/relation/where_clause.rb
|
249
|
+
- lib/active_record/relation/where_clause_factory.rb
|
196
250
|
- lib/active_record/result.rb
|
251
|
+
- lib/active_record/runtime_registry.rb
|
197
252
|
- lib/active_record/sanitization.rb
|
198
253
|
- lib/active_record/schema.rb
|
199
254
|
- lib/active_record/schema_dumper.rb
|
255
|
+
- lib/active_record/schema_migration.rb
|
200
256
|
- lib/active_record/scoping.rb
|
201
257
|
- lib/active_record/scoping/default.rb
|
202
258
|
- lib/active_record/scoping/named.rb
|
259
|
+
- lib/active_record/secure_token.rb
|
203
260
|
- lib/active_record/serialization.rb
|
204
|
-
- lib/active_record/
|
205
|
-
- lib/active_record/session_store.rb
|
261
|
+
- lib/active_record/statement_cache.rb
|
206
262
|
- lib/active_record/store.rb
|
207
|
-
- lib/active_record/
|
263
|
+
- lib/active_record/suppressor.rb
|
264
|
+
- lib/active_record/table_metadata.rb
|
265
|
+
- lib/active_record/tasks/database_tasks.rb
|
266
|
+
- lib/active_record/tasks/mysql_database_tasks.rb
|
267
|
+
- lib/active_record/tasks/postgresql_database_tasks.rb
|
268
|
+
- lib/active_record/tasks/sqlite_database_tasks.rb
|
208
269
|
- lib/active_record/timestamp.rb
|
270
|
+
- lib/active_record/touch_later.rb
|
209
271
|
- lib/active_record/transactions.rb
|
210
272
|
- lib/active_record/translation.rb
|
273
|
+
- lib/active_record/type.rb
|
274
|
+
- lib/active_record/type/adapter_specific_registry.rb
|
275
|
+
- lib/active_record/type/date.rb
|
276
|
+
- lib/active_record/type/date_time.rb
|
277
|
+
- lib/active_record/type/decimal_without_scale.rb
|
278
|
+
- lib/active_record/type/hash_lookup_type_map.rb
|
279
|
+
- lib/active_record/type/internal/timezone.rb
|
280
|
+
- lib/active_record/type/json.rb
|
281
|
+
- lib/active_record/type/serialized.rb
|
282
|
+
- lib/active_record/type/text.rb
|
283
|
+
- lib/active_record/type/time.rb
|
284
|
+
- lib/active_record/type/type_map.rb
|
285
|
+
- lib/active_record/type/unsigned_integer.rb
|
286
|
+
- lib/active_record/type_caster.rb
|
287
|
+
- lib/active_record/type_caster/connection.rb
|
288
|
+
- lib/active_record/type_caster/map.rb
|
211
289
|
- lib/active_record/validations.rb
|
290
|
+
- lib/active_record/validations/absence.rb
|
212
291
|
- lib/active_record/validations/associated.rb
|
292
|
+
- lib/active_record/validations/length.rb
|
293
|
+
- lib/active_record/validations/presence.rb
|
213
294
|
- lib/active_record/validations/uniqueness.rb
|
214
295
|
- lib/active_record/version.rb
|
215
296
|
- lib/rails/generators/active_record.rb
|
297
|
+
- lib/rails/generators/active_record/application_record/application_record_generator.rb
|
298
|
+
- lib/rails/generators/active_record/application_record/templates/application_record.rb.tt
|
216
299
|
- lib/rails/generators/active_record/migration.rb
|
217
300
|
- lib/rails/generators/active_record/migration/migration_generator.rb
|
218
|
-
- lib/rails/generators/active_record/migration/templates/
|
301
|
+
- lib/rails/generators/active_record/migration/templates/create_table_migration.rb.tt
|
302
|
+
- lib/rails/generators/active_record/migration/templates/migration.rb.tt
|
219
303
|
- lib/rails/generators/active_record/model/model_generator.rb
|
220
|
-
- lib/rails/generators/active_record/model/templates/
|
221
|
-
- lib/rails/generators/active_record/model/templates/
|
222
|
-
|
223
|
-
- lib/rails/generators/active_record/observer/observer_generator.rb
|
224
|
-
- lib/rails/generators/active_record/observer/templates/observer.rb
|
225
|
-
- lib/rails/generators/active_record/session_migration/session_migration_generator.rb
|
226
|
-
- lib/rails/generators/active_record/session_migration/templates/migration.rb
|
227
|
-
homepage: http://www.rubyonrails.org
|
304
|
+
- lib/rails/generators/active_record/model/templates/model.rb.tt
|
305
|
+
- lib/rails/generators/active_record/model/templates/module.rb.tt
|
306
|
+
homepage: http://rubyonrails.org
|
228
307
|
licenses:
|
229
308
|
- MIT
|
230
|
-
metadata:
|
309
|
+
metadata:
|
310
|
+
source_code_uri: https://github.com/rails/rails/tree/v5.2.8/activerecord
|
311
|
+
changelog_uri: https://github.com/rails/rails/blob/v5.2.8/activerecord/CHANGELOG.md
|
231
312
|
post_install_message:
|
232
313
|
rdoc_options:
|
233
314
|
- "--main"
|
@@ -238,17 +319,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
238
319
|
requirements:
|
239
320
|
- - ">="
|
240
321
|
- !ruby/object:Gem::Version
|
241
|
-
version:
|
322
|
+
version: 2.2.2
|
242
323
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
243
324
|
requirements:
|
244
325
|
- - ">="
|
245
326
|
- !ruby/object:Gem::Version
|
246
327
|
version: '0'
|
247
328
|
requirements: []
|
248
|
-
|
249
|
-
rubygems_version: 2.6.6
|
329
|
+
rubygems_version: 3.1.6
|
250
330
|
signing_key:
|
251
331
|
specification_version: 4
|
252
332
|
summary: Object-relational mapper framework (part of Rails).
|
253
333
|
test_files: []
|
254
|
-
has_rdoc:
|
data/examples/associations.png
DELETED
Binary file
|
@@ -1,63 +0,0 @@
|
|
1
|
-
module ActiveRecord
|
2
|
-
# = Active Record Has And Belongs To Many Association
|
3
|
-
module Associations
|
4
|
-
class HasAndBelongsToManyAssociation < CollectionAssociation #:nodoc:
|
5
|
-
attr_reader :join_table
|
6
|
-
|
7
|
-
def initialize(owner, reflection)
|
8
|
-
@join_table = Arel::Table.new(reflection.options[:join_table])
|
9
|
-
super
|
10
|
-
end
|
11
|
-
|
12
|
-
def insert_record(record, validate = true, raise = false)
|
13
|
-
if record.new_record?
|
14
|
-
if raise
|
15
|
-
record.save!(:validate => validate)
|
16
|
-
else
|
17
|
-
return unless record.save(:validate => validate)
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
if options[:insert_sql]
|
22
|
-
owner.connection.insert(interpolate(options[:insert_sql], record))
|
23
|
-
else
|
24
|
-
stmt = join_table.compile_insert(
|
25
|
-
join_table[reflection.foreign_key] => owner.id,
|
26
|
-
join_table[reflection.association_foreign_key] => record.id
|
27
|
-
)
|
28
|
-
|
29
|
-
owner.connection.insert stmt
|
30
|
-
end
|
31
|
-
|
32
|
-
record
|
33
|
-
end
|
34
|
-
|
35
|
-
# ActiveRecord::Relation#delete_all needs to support joins before we can use a
|
36
|
-
# SQL-only implementation.
|
37
|
-
alias delete_all_on_destroy delete_all
|
38
|
-
|
39
|
-
private
|
40
|
-
|
41
|
-
def count_records
|
42
|
-
load_target.size
|
43
|
-
end
|
44
|
-
|
45
|
-
def delete_records(records, method)
|
46
|
-
if sql = options[:delete_sql]
|
47
|
-
records = load_target if records == :all
|
48
|
-
records.each { |record| owner.connection.delete(interpolate(sql, record)) }
|
49
|
-
else
|
50
|
-
relation = join_table
|
51
|
-
stmt = relation.where(relation[reflection.foreign_key].eq(owner.id).
|
52
|
-
and(relation[reflection.association_foreign_key].in(records.map { |x| x.id }.compact))
|
53
|
-
).compile_delete
|
54
|
-
owner.connection.delete stmt
|
55
|
-
end
|
56
|
-
end
|
57
|
-
|
58
|
-
def invertible_for?(record)
|
59
|
-
false
|
60
|
-
end
|
61
|
-
end
|
62
|
-
end
|
63
|
-
end
|
@@ -1,55 +0,0 @@
|
|
1
|
-
module ActiveRecord
|
2
|
-
module Associations
|
3
|
-
# Helper class module which gets mixed into JoinDependency::JoinAssociation and AssociationScope
|
4
|
-
module JoinHelper #:nodoc:
|
5
|
-
|
6
|
-
def join_type
|
7
|
-
Arel::InnerJoin
|
8
|
-
end
|
9
|
-
|
10
|
-
private
|
11
|
-
|
12
|
-
def construct_tables
|
13
|
-
tables = []
|
14
|
-
chain.each do |reflection|
|
15
|
-
tables << alias_tracker.aliased_table_for(
|
16
|
-
table_name_for(reflection),
|
17
|
-
table_alias_for(reflection, reflection != self.reflection)
|
18
|
-
)
|
19
|
-
|
20
|
-
if reflection.source_macro == :has_and_belongs_to_many
|
21
|
-
tables << alias_tracker.aliased_table_for(
|
22
|
-
(reflection.source_reflection || reflection).options[:join_table],
|
23
|
-
table_alias_for(reflection, true)
|
24
|
-
)
|
25
|
-
end
|
26
|
-
end
|
27
|
-
tables
|
28
|
-
end
|
29
|
-
|
30
|
-
def table_name_for(reflection)
|
31
|
-
reflection.table_name
|
32
|
-
end
|
33
|
-
|
34
|
-
def table_alias_for(reflection, join = false)
|
35
|
-
name = "#{reflection.plural_name}_#{alias_suffix}"
|
36
|
-
name << "_join" if join
|
37
|
-
name
|
38
|
-
end
|
39
|
-
|
40
|
-
def join(table, constraint)
|
41
|
-
table.create_join(table, table.create_on(constraint), join_type)
|
42
|
-
end
|
43
|
-
|
44
|
-
def sanitize(conditions, table)
|
45
|
-
conditions = conditions.map do |condition|
|
46
|
-
condition = active_record.send(:sanitize_sql, interpolate(condition), table.table_alias || table.name)
|
47
|
-
condition = Arel.sql(condition) unless condition.is_a?(Arel::Node)
|
48
|
-
condition
|
49
|
-
end
|
50
|
-
|
51
|
-
conditions.length == 1 ? conditions.first : Arel::Nodes::And.new(conditions)
|
52
|
-
end
|
53
|
-
end
|
54
|
-
end
|
55
|
-
end
|
@@ -1,17 +0,0 @@
|
|
1
|
-
module ActiveRecord
|
2
|
-
module Associations
|
3
|
-
class Preloader
|
4
|
-
class BelongsTo < SingularAssociation #:nodoc:
|
5
|
-
|
6
|
-
def association_key_name
|
7
|
-
reflection.options[:primary_key] || klass && klass.primary_key
|
8
|
-
end
|
9
|
-
|
10
|
-
def owner_key_name
|
11
|
-
reflection.foreign_key
|
12
|
-
end
|
13
|
-
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
@@ -1,24 +0,0 @@
|
|
1
|
-
module ActiveRecord
|
2
|
-
module Associations
|
3
|
-
class Preloader
|
4
|
-
class CollectionAssociation < Association #:nodoc:
|
5
|
-
|
6
|
-
private
|
7
|
-
|
8
|
-
def build_scope
|
9
|
-
super.order(preload_options[:order] || options[:order])
|
10
|
-
end
|
11
|
-
|
12
|
-
def preload
|
13
|
-
associated_records_by_owner.each do |owner, records|
|
14
|
-
association = owner.association(reflection.name)
|
15
|
-
association.loaded!
|
16
|
-
association.target.concat(records)
|
17
|
-
records.each { |record| association.set_inverse_instance(record) }
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|
@@ -1,60 +0,0 @@
|
|
1
|
-
module ActiveRecord
|
2
|
-
module Associations
|
3
|
-
class Preloader
|
4
|
-
class HasAndBelongsToMany < CollectionAssociation #:nodoc:
|
5
|
-
attr_reader :join_table
|
6
|
-
|
7
|
-
def initialize(klass, records, reflection, preload_options)
|
8
|
-
super
|
9
|
-
@join_table = Arel::Table.new(options[:join_table]).alias('t0')
|
10
|
-
end
|
11
|
-
|
12
|
-
# Unlike the other associations, we want to get a raw array of rows so that we can
|
13
|
-
# access the aliased column on the join table
|
14
|
-
def records_for(ids)
|
15
|
-
scope = super
|
16
|
-
klass.connection.select_all(scope.arel, 'SQL', scope.bind_values)
|
17
|
-
end
|
18
|
-
|
19
|
-
def owner_key_name
|
20
|
-
reflection.active_record_primary_key
|
21
|
-
end
|
22
|
-
|
23
|
-
def association_key_name
|
24
|
-
'ar_association_key_name'
|
25
|
-
end
|
26
|
-
|
27
|
-
def association_key
|
28
|
-
join_table[reflection.foreign_key]
|
29
|
-
end
|
30
|
-
|
31
|
-
private
|
32
|
-
|
33
|
-
# Once we have used the join table column (in super), we manually instantiate the
|
34
|
-
# actual records, ensuring that we don't create more than one instances of the same
|
35
|
-
# record
|
36
|
-
def associated_records_by_owner
|
37
|
-
records = {}
|
38
|
-
super.each do |owner_key, rows|
|
39
|
-
rows.map! { |row| records[row[klass.primary_key]] ||= klass.instantiate(row) }
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
def build_scope
|
44
|
-
super.joins(join).select(join_select)
|
45
|
-
end
|
46
|
-
|
47
|
-
def join_select
|
48
|
-
association_key.as(Arel.sql(association_key_name))
|
49
|
-
end
|
50
|
-
|
51
|
-
def join
|
52
|
-
condition = table[reflection.association_primary_key].eq(
|
53
|
-
join_table[reflection.association_foreign_key])
|
54
|
-
|
55
|
-
table.create_join(join_table, table.create_on(condition))
|
56
|
-
end
|
57
|
-
end
|
58
|
-
end
|
59
|
-
end
|
60
|
-
end
|
@@ -1,17 +0,0 @@
|
|
1
|
-
module ActiveRecord
|
2
|
-
module Associations
|
3
|
-
class Preloader
|
4
|
-
class HasMany < CollectionAssociation #:nodoc:
|
5
|
-
|
6
|
-
def association_key_name
|
7
|
-
reflection.foreign_key
|
8
|
-
end
|
9
|
-
|
10
|
-
def owner_key_name
|
11
|
-
reflection.active_record_primary_key
|
12
|
-
end
|
13
|
-
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
@@ -1,15 +0,0 @@
|
|
1
|
-
module ActiveRecord
|
2
|
-
module Associations
|
3
|
-
class Preloader
|
4
|
-
class HasManyThrough < CollectionAssociation #:nodoc:
|
5
|
-
include ThroughAssociation
|
6
|
-
|
7
|
-
def associated_records_by_owner
|
8
|
-
super.each do |owner, records|
|
9
|
-
records.uniq! if options[:uniq]
|
10
|
-
end
|
11
|
-
end
|
12
|
-
end
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|
@@ -1,23 +0,0 @@
|
|
1
|
-
module ActiveRecord
|
2
|
-
module Associations
|
3
|
-
class Preloader
|
4
|
-
class HasOne < SingularAssociation #:nodoc:
|
5
|
-
|
6
|
-
def association_key_name
|
7
|
-
reflection.foreign_key
|
8
|
-
end
|
9
|
-
|
10
|
-
def owner_key_name
|
11
|
-
reflection.active_record_primary_key
|
12
|
-
end
|
13
|
-
|
14
|
-
private
|
15
|
-
|
16
|
-
def build_scope
|
17
|
-
super.order(preload_options[:order] || options[:order])
|
18
|
-
end
|
19
|
-
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|