activerecord 5.1.0 → 5.2.0.rc1
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 +410 -530
- data/MIT-LICENSE +1 -1
- data/README.rdoc +4 -4
- data/examples/performance.rb +2 -0
- data/examples/simple.rb +2 -0
- data/lib/active_record/aggregations.rb +6 -5
- data/lib/active_record/association_relation.rb +4 -2
- data/lib/active_record/associations/alias_tracker.rb +23 -32
- data/lib/active_record/associations/association.rb +20 -21
- data/lib/active_record/associations/association_scope.rb +49 -49
- data/lib/active_record/associations/belongs_to_association.rb +12 -10
- data/lib/active_record/associations/belongs_to_polymorphic_association.rb +4 -7
- data/lib/active_record/associations/builder/association.rb +4 -7
- data/lib/active_record/associations/builder/belongs_to.rb +10 -6
- data/lib/active_record/associations/builder/collection_association.rb +1 -1
- data/lib/active_record/associations/builder/has_and_belongs_to_many.rb +3 -1
- data/lib/active_record/associations/builder/has_many.rb +2 -0
- data/lib/active_record/associations/builder/has_one.rb +2 -0
- data/lib/active_record/associations/builder/singular_association.rb +2 -0
- data/lib/active_record/associations/collection_association.rb +50 -41
- data/lib/active_record/associations/collection_proxy.rb +22 -39
- data/lib/active_record/associations/foreign_association.rb +2 -0
- data/lib/active_record/associations/has_many_association.rb +4 -2
- data/lib/active_record/associations/has_many_through_association.rb +12 -18
- data/lib/active_record/associations/has_one_association.rb +5 -1
- data/lib/active_record/associations/has_one_through_association.rb +8 -7
- data/lib/active_record/associations/join_dependency/join_association.rb +17 -64
- data/lib/active_record/associations/join_dependency/join_base.rb +9 -8
- data/lib/active_record/associations/join_dependency/join_part.rb +2 -9
- data/lib/active_record/associations/join_dependency.rb +27 -44
- data/lib/active_record/associations/preloader/association.rb +53 -92
- data/lib/active_record/associations/preloader/through_association.rb +72 -73
- data/lib/active_record/associations/preloader.rb +17 -37
- data/lib/active_record/associations/singular_association.rb +14 -10
- data/lib/active_record/associations/through_association.rb +26 -11
- data/lib/active_record/associations.rb +68 -76
- data/lib/active_record/attribute_assignment.rb +2 -0
- data/lib/active_record/attribute_decorators.rb +3 -2
- data/lib/active_record/attribute_methods/before_type_cast.rb +2 -0
- data/lib/active_record/attribute_methods/dirty.rb +24 -214
- data/lib/active_record/attribute_methods/primary_key.rb +10 -13
- data/lib/active_record/attribute_methods/query.rb +2 -0
- data/lib/active_record/attribute_methods/read.rb +8 -2
- data/lib/active_record/attribute_methods/serialization.rb +23 -0
- data/lib/active_record/attribute_methods/time_zone_conversion.rb +6 -8
- data/lib/active_record/attribute_methods/write.rb +22 -19
- data/lib/active_record/attribute_methods.rb +48 -12
- data/lib/active_record/attributes.rb +7 -6
- data/lib/active_record/autosave_association.rb +8 -11
- data/lib/active_record/base.rb +2 -0
- data/lib/active_record/callbacks.rb +8 -6
- data/lib/active_record/coders/json.rb +2 -0
- data/lib/active_record/coders/yaml_column.rb +2 -0
- data/lib/active_record/collection_cache_key.rb +14 -10
- data/lib/active_record/connection_adapters/abstract/connection_pool.rb +110 -35
- data/lib/active_record/connection_adapters/abstract/database_limits.rb +2 -0
- data/lib/active_record/connection_adapters/abstract/database_statements.rb +175 -33
- data/lib/active_record/connection_adapters/abstract/query_cache.rb +8 -2
- data/lib/active_record/connection_adapters/abstract/quoting.rb +13 -24
- data/lib/active_record/connection_adapters/abstract/savepoints.rb +2 -0
- data/lib/active_record/connection_adapters/abstract/schema_creation.rb +15 -6
- data/lib/active_record/connection_adapters/abstract/schema_definitions.rb +58 -3
- data/lib/active_record/connection_adapters/abstract/schema_dumper.rb +31 -53
- data/lib/active_record/connection_adapters/abstract/schema_statements.rb +165 -85
- data/lib/active_record/connection_adapters/abstract/transaction.rb +45 -9
- data/lib/active_record/connection_adapters/abstract_adapter.rb +83 -97
- data/lib/active_record/connection_adapters/abstract_mysql_adapter.rb +118 -180
- data/lib/active_record/connection_adapters/column.rb +4 -2
- data/lib/active_record/connection_adapters/connection_specification.rb +17 -3
- data/lib/active_record/connection_adapters/determine_if_preparable_visitor.rb +2 -0
- data/lib/active_record/connection_adapters/mysql/column.rb +2 -0
- data/lib/active_record/connection_adapters/mysql/database_statements.rb +11 -17
- data/lib/active_record/connection_adapters/mysql/explain_pretty_printer.rb +2 -0
- data/lib/active_record/connection_adapters/mysql/quoting.rb +9 -10
- data/lib/active_record/connection_adapters/mysql/schema_creation.rb +5 -3
- data/lib/active_record/connection_adapters/mysql/schema_definitions.rb +7 -10
- data/lib/active_record/connection_adapters/mysql/schema_dumper.rb +30 -23
- data/lib/active_record/connection_adapters/mysql/schema_statements.rb +106 -1
- data/lib/active_record/connection_adapters/mysql/type_metadata.rb +2 -0
- data/lib/active_record/connection_adapters/mysql2_adapter.rb +8 -2
- data/lib/active_record/connection_adapters/postgresql/column.rb +30 -1
- data/lib/active_record/connection_adapters/postgresql/database_statements.rb +6 -32
- data/lib/active_record/connection_adapters/postgresql/explain_pretty_printer.rb +2 -0
- data/lib/active_record/connection_adapters/postgresql/oid/array.rb +2 -0
- data/lib/active_record/connection_adapters/postgresql/oid/bit.rb +2 -0
- 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 +2 -0
- data/lib/active_record/connection_adapters/postgresql/oid/date_time.rb +2 -0
- data/lib/active_record/connection_adapters/postgresql/oid/decimal.rb +3 -1
- data/lib/active_record/connection_adapters/postgresql/oid/enum.rb +2 -0
- data/lib/active_record/connection_adapters/postgresql/oid/hstore.rb +2 -0
- 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 +2 -0
- data/lib/active_record/connection_adapters/postgresql/oid/money.rb +3 -1
- data/lib/active_record/connection_adapters/postgresql/oid/oid.rb +2 -0
- data/lib/active_record/connection_adapters/postgresql/oid/point.rb +2 -0
- data/lib/active_record/connection_adapters/postgresql/oid/range.rb +4 -2
- data/lib/active_record/connection_adapters/postgresql/oid/specialized_string.rb +2 -0
- data/lib/active_record/connection_adapters/postgresql/oid/type_map_initializer.rb +4 -2
- data/lib/active_record/connection_adapters/postgresql/oid/uuid.rb +3 -1
- 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 +2 -1
- data/lib/active_record/connection_adapters/postgresql/quoting.rb +22 -1
- data/lib/active_record/connection_adapters/postgresql/referential_integrity.rb +19 -25
- data/lib/active_record/connection_adapters/postgresql/schema_creation.rb +14 -0
- data/lib/active_record/connection_adapters/postgresql/schema_definitions.rb +24 -11
- data/lib/active_record/connection_adapters/postgresql/schema_dumper.rb +20 -13
- data/lib/active_record/connection_adapters/postgresql/schema_statements.rb +269 -126
- data/lib/active_record/connection_adapters/postgresql/type_metadata.rb +2 -0
- data/lib/active_record/connection_adapters/postgresql/utils.rb +2 -0
- data/lib/active_record/connection_adapters/postgresql_adapter.rb +64 -85
- data/lib/active_record/connection_adapters/schema_cache.rb +4 -2
- data/lib/active_record/connection_adapters/sql_type_metadata.rb +2 -0
- data/lib/active_record/connection_adapters/sqlite3/explain_pretty_printer.rb +2 -0
- data/lib/active_record/connection_adapters/sqlite3/quoting.rb +18 -0
- data/lib/active_record/connection_adapters/sqlite3/schema_creation.rb +2 -0
- data/lib/active_record/connection_adapters/sqlite3/schema_definitions.rb +6 -15
- data/lib/active_record/connection_adapters/sqlite3/schema_dumper.rb +3 -2
- data/lib/active_record/connection_adapters/sqlite3/schema_statements.rb +71 -1
- data/lib/active_record/connection_adapters/sqlite3_adapter.rb +92 -95
- data/lib/active_record/connection_adapters/statement_pool.rb +2 -0
- data/lib/active_record/connection_handling.rb +4 -2
- data/lib/active_record/core.rb +39 -60
- data/lib/active_record/counter_cache.rb +3 -2
- data/lib/active_record/define_callbacks.rb +5 -3
- data/lib/active_record/dynamic_matchers.rb +9 -9
- data/lib/active_record/enum.rb +17 -13
- data/lib/active_record/errors.rb +42 -3
- data/lib/active_record/explain.rb +3 -1
- data/lib/active_record/explain_registry.rb +2 -0
- data/lib/active_record/explain_subscriber.rb +2 -0
- data/lib/active_record/fixture_set/file.rb +2 -0
- data/lib/active_record/fixtures.rb +67 -60
- data/lib/active_record/gem_version.rb +4 -2
- data/lib/active_record/inheritance.rb +9 -9
- data/lib/active_record/integration.rb +58 -19
- data/lib/active_record/internal_metadata.rb +2 -0
- data/lib/active_record/legacy_yaml_adapter.rb +3 -1
- data/lib/active_record/locking/optimistic.rb +8 -6
- data/lib/active_record/locking/pessimistic.rb +9 -6
- data/lib/active_record/log_subscriber.rb +46 -4
- data/lib/active_record/migration/command_recorder.rb +11 -9
- data/lib/active_record/migration/compatibility.rb +74 -22
- data/lib/active_record/migration/join_table.rb +2 -0
- data/lib/active_record/migration.rb +181 -137
- data/lib/active_record/model_schema.rb +73 -58
- data/lib/active_record/nested_attributes.rb +18 -6
- data/lib/active_record/no_touching.rb +3 -1
- data/lib/active_record/null_relation.rb +2 -0
- data/lib/active_record/persistence.rb +153 -18
- data/lib/active_record/query_cache.rb +17 -12
- data/lib/active_record/querying.rb +4 -2
- data/lib/active_record/railtie.rb +61 -3
- data/lib/active_record/railties/console_sandbox.rb +2 -0
- data/lib/active_record/railties/controller_runtime.rb +2 -0
- data/lib/active_record/railties/databases.rake +47 -37
- data/lib/active_record/readonly_attributes.rb +3 -2
- data/lib/active_record/reflection.rb +131 -204
- data/lib/active_record/relation/batches/batch_enumerator.rb +2 -0
- data/lib/active_record/relation/batches.rb +32 -17
- data/lib/active_record/relation/calculations.rb +58 -20
- data/lib/active_record/relation/delegation.rb +10 -29
- data/lib/active_record/relation/finder_methods.rb +74 -85
- data/lib/active_record/relation/from_clause.rb +2 -8
- data/lib/active_record/relation/merger.rb +51 -20
- data/lib/active_record/relation/predicate_builder/array_handler.rb +10 -7
- data/lib/active_record/relation/predicate_builder/association_query_value.rb +46 -0
- data/lib/active_record/relation/predicate_builder/base_handler.rb +2 -2
- data/lib/active_record/relation/predicate_builder/basic_object_handler.rb +12 -1
- data/lib/active_record/relation/predicate_builder/polymorphic_array_value.rb +54 -0
- data/lib/active_record/relation/predicate_builder/range_handler.rb +22 -6
- data/lib/active_record/relation/predicate_builder/relation_handler.rb +6 -0
- data/lib/active_record/relation/predicate_builder.rb +53 -78
- data/lib/active_record/relation/query_attribute.rb +9 -2
- data/lib/active_record/relation/query_methods.rb +101 -95
- data/lib/active_record/relation/record_fetch_warning.rb +2 -0
- data/lib/active_record/relation/spawn_methods.rb +3 -1
- data/lib/active_record/relation/where_clause.rb +65 -67
- data/lib/active_record/relation/where_clause_factory.rb +5 -48
- data/lib/active_record/relation.rb +99 -202
- data/lib/active_record/result.rb +2 -0
- data/lib/active_record/runtime_registry.rb +2 -0
- data/lib/active_record/sanitization.rb +129 -121
- data/lib/active_record/schema.rb +4 -2
- data/lib/active_record/schema_dumper.rb +36 -26
- data/lib/active_record/schema_migration.rb +2 -0
- data/lib/active_record/scoping/default.rb +10 -7
- data/lib/active_record/scoping/named.rb +38 -12
- data/lib/active_record/scoping.rb +12 -10
- data/lib/active_record/secure_token.rb +2 -0
- data/lib/active_record/serialization.rb +2 -0
- data/lib/active_record/statement_cache.rb +22 -12
- data/lib/active_record/store.rb +3 -1
- data/lib/active_record/suppressor.rb +2 -0
- data/lib/active_record/table_metadata.rb +12 -3
- data/lib/active_record/tasks/database_tasks.rb +37 -25
- data/lib/active_record/tasks/mysql_database_tasks.rb +11 -50
- data/lib/active_record/tasks/postgresql_database_tasks.rb +11 -3
- data/lib/active_record/tasks/sqlite_database_tasks.rb +25 -3
- data/lib/active_record/timestamp.rb +5 -5
- data/lib/active_record/touch_later.rb +2 -0
- data/lib/active_record/transactions.rb +9 -7
- data/lib/active_record/translation.rb +2 -0
- data/lib/active_record/type/adapter_specific_registry.rb +2 -0
- 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 +2 -0
- data/lib/active_record/type/hash_lookup_type_map.rb +2 -0
- 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 +2 -0
- data/lib/active_record/type/text.rb +2 -0
- data/lib/active_record/type/time.rb +2 -0
- data/lib/active_record/type/type_map.rb +2 -0
- data/lib/active_record/type/unsigned_integer.rb +2 -0
- data/lib/active_record/type.rb +4 -1
- data/lib/active_record/type_caster/connection.rb +2 -0
- data/lib/active_record/type_caster/map.rb +3 -1
- data/lib/active_record/type_caster.rb +2 -0
- data/lib/active_record/validations/absence.rb +2 -0
- data/lib/active_record/validations/associated.rb +2 -0
- data/lib/active_record/validations/length.rb +2 -0
- data/lib/active_record/validations/presence.rb +2 -0
- data/lib/active_record/validations/uniqueness.rb +35 -5
- data/lib/active_record/validations.rb +2 -0
- data/lib/active_record/version.rb +2 -0
- data/lib/active_record.rb +11 -4
- 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 +3 -1
- data/lib/rails/generators/active_record/migration/templates/{create_table_migration.rb → create_table_migration.rb.tt} +0 -0
- data/lib/rails/generators/active_record/migration/templates/{migration.rb → migration.rb.tt} +0 -0
- data/lib/rails/generators/active_record/migration.rb +2 -0
- data/lib/rails/generators/active_record/model/model_generator.rb +2 -23
- data/lib/rails/generators/active_record/model/templates/{model.rb → model.rb.tt} +0 -0
- data/lib/rails/generators/active_record/model/templates/{module.rb → module.rb.tt} +0 -0
- data/lib/rails/generators/active_record.rb +3 -1
- metadata +25 -37
- data/lib/active_record/associations/preloader/belongs_to.rb +0 -15
- data/lib/active_record/associations/preloader/collection_association.rb +0 -17
- data/lib/active_record/associations/preloader/has_many.rb +0 -15
- 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 -18
- data/lib/active_record/attribute/user_provided_default.rb +0 -30
- data/lib/active_record/attribute.rb +0 -240
- data/lib/active_record/attribute_mutation_tracker.rb +0 -113
- data/lib/active_record/attribute_set/builder.rb +0 -124
- data/lib/active_record/attribute_set/yaml_encoder.rb +0 -41
- data/lib/active_record/attribute_set.rb +0 -113
- data/lib/active_record/connection_adapters/postgresql/oid/json.rb +0 -10
- 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/polymorphic_array_handler.rb +0 -59
- data/lib/active_record/type/internal/abstract_json.rb +0 -33
data/lib/active_record/type.rb
CHANGED
@@ -1,11 +1,13 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require "active_model/type"
|
2
4
|
|
3
|
-
require "active_record/type/internal/abstract_json"
|
4
5
|
require "active_record/type/internal/timezone"
|
5
6
|
|
6
7
|
require "active_record/type/date"
|
7
8
|
require "active_record/type/date_time"
|
8
9
|
require "active_record/type/decimal_without_scale"
|
10
|
+
require "active_record/type/json"
|
9
11
|
require "active_record/type/time"
|
10
12
|
require "active_record/type/text"
|
11
13
|
require "active_record/type/unsigned_integer"
|
@@ -69,6 +71,7 @@ module ActiveRecord
|
|
69
71
|
register(:decimal, Type::Decimal, override: false)
|
70
72
|
register(:float, Type::Float, override: false)
|
71
73
|
register(:integer, Type::Integer, override: false)
|
74
|
+
register(:json, Type::Json, override: false)
|
72
75
|
register(:string, Type::String, override: false)
|
73
76
|
register(:text, Type::Text, override: false)
|
74
77
|
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 Map # :nodoc:
|
@@ -7,7 +9,7 @@ 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
|
|
@@ -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,6 +8,10 @@ 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
|
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
|
9
15
|
super({ case_sensitive: true }.merge!(options))
|
10
16
|
@klass = options[:class]
|
11
17
|
end
|
@@ -50,7 +56,33 @@ module ActiveRecord
|
|
50
56
|
end
|
51
57
|
|
52
58
|
def build_relation(klass, attribute, value)
|
53
|
-
klass.
|
59
|
+
if reflection = klass._reflect_on_association(attribute)
|
60
|
+
attribute = reflection.foreign_key
|
61
|
+
value = value.attributes[reflection.klass.primary_key] unless value.nil?
|
62
|
+
end
|
63
|
+
|
64
|
+
if value.nil?
|
65
|
+
return klass.unscoped.where!(attribute => value)
|
66
|
+
end
|
67
|
+
|
68
|
+
# the attribute may be an aliased attribute
|
69
|
+
if klass.attribute_alias?(attribute)
|
70
|
+
attribute = klass.attribute_alias(attribute)
|
71
|
+
end
|
72
|
+
|
73
|
+
attribute_name = attribute.to_s
|
74
|
+
value = klass.predicate_builder.build_bind_attribute(attribute_name, value)
|
75
|
+
|
76
|
+
table = klass.arel_table
|
77
|
+
column = klass.columns_hash[attribute_name]
|
78
|
+
|
79
|
+
comparison = if !options[:case_sensitive]
|
80
|
+
# will use SQL LOWER function before comparison, unless it detects a case insensitive collation
|
81
|
+
klass.connection.case_insensitive_comparison(table, attribute, column, value)
|
82
|
+
else
|
83
|
+
klass.connection.case_sensitive_comparison(table, attribute, column, value)
|
84
|
+
end
|
85
|
+
klass.unscoped.where!(comparison)
|
54
86
|
end
|
55
87
|
|
56
88
|
def scope_relation(record, relation)
|
@@ -173,9 +205,7 @@ module ActiveRecord
|
|
173
205
|
# | # Boom! We now have a duplicate
|
174
206
|
# | # title!
|
175
207
|
#
|
176
|
-
#
|
177
|
-
# isolation level. The best way to work around this problem is to add a unique
|
178
|
-
# index to the database table using
|
208
|
+
# The best way to work around this problem is to add a unique index to the database table using
|
179
209
|
# {connection.add_index}[rdoc-ref:ConnectionAdapters::SchemaStatements#add_index].
|
180
210
|
# In the rare case that a race condition occurs, the database will guarantee
|
181
211
|
# the field's uniqueness.
|
@@ -187,7 +217,7 @@ module ActiveRecord
|
|
187
217
|
# can catch it and restart the transaction (e.g. by telling the user
|
188
218
|
# that the title already exists, and asking them to re-enter the title).
|
189
219
|
# This technique is also known as
|
190
|
-
# {optimistic concurrency control}[
|
220
|
+
# {optimistic concurrency control}[https://en.wikipedia.org/wiki/Optimistic_concurrency_control].
|
191
221
|
#
|
192
222
|
# The bundled ActiveRecord::ConnectionAdapters distinguish unique index
|
193
223
|
# constraint errors from other types of database errors by throwing an
|
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-2018 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
|
@@ -25,14 +27,14 @@ require "active_support"
|
|
25
27
|
require "active_support/rails"
|
26
28
|
require "active_model"
|
27
29
|
require "arel"
|
30
|
+
require "yaml"
|
28
31
|
|
29
32
|
require "active_record/version"
|
30
|
-
require "
|
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
|
@@ -102,6 +104,7 @@ module ActiveRecord
|
|
102
104
|
|
103
105
|
autoload :Result
|
104
106
|
autoload :TableMetadata
|
107
|
+
autoload :Type
|
105
108
|
end
|
106
109
|
|
107
110
|
module Coders
|
@@ -177,5 +180,9 @@ ActiveSupport.on_load(:active_record) do
|
|
177
180
|
end
|
178
181
|
|
179
182
|
ActiveSupport.on_load(:i18n) do
|
180
|
-
I18n.load_path << File.
|
183
|
+
I18n.load_path << File.expand_path("active_record/locale/en.yml", __dir__)
|
181
184
|
end
|
185
|
+
|
186
|
+
YAML.load_tags["!ruby/object:ActiveRecord::AttributeSet"] = "ActiveModel::AttributeSet"
|
187
|
+
YAML.load_tags["!ruby/object:ActiveRecord::Attribute::FromDatabase"] = "ActiveModel::Attribute::FromDatabase"
|
188
|
+
YAML.load_tags["!ruby/object:ActiveRecord::LazyAttributeHash"] = "ActiveModel::LazyAttributeHash"
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "rails/generators/active_record"
|
4
|
+
|
5
|
+
module ActiveRecord
|
6
|
+
module Generators # :nodoc:
|
7
|
+
class ApplicationRecordGenerator < ::Rails::Generators::Base # :nodoc:
|
8
|
+
source_root File.expand_path("templates", __dir__)
|
9
|
+
|
10
|
+
# FIXME: Change this file to a symlink once RubyGems 2.5.0 is required.
|
11
|
+
def create_application_record
|
12
|
+
template "application_record.rb", application_record_file_name
|
13
|
+
end
|
14
|
+
|
15
|
+
private
|
16
|
+
|
17
|
+
def application_record_file_name
|
18
|
+
@application_record_file_name ||=
|
19
|
+
if namespaced?
|
20
|
+
"app/models/#{namespaced_path}/application_record.rb"
|
21
|
+
else
|
22
|
+
"app/models/application_record.rb"
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
File without changes
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require "rails/generators/active_record"
|
2
4
|
|
3
5
|
module ActiveRecord
|
@@ -26,7 +28,7 @@ module ActiveRecord
|
|
26
28
|
def set_local_assigns!
|
27
29
|
@migration_template = "migration.rb"
|
28
30
|
case file_name
|
29
|
-
when /^(add
|
31
|
+
when /^(add)_.*_to_(.*)/, /^(remove)_.*?_from_(.*)/
|
30
32
|
@migration_action = $1
|
31
33
|
@table_name = normalize_table_name($2)
|
32
34
|
when /join_table/
|
File without changes
|
data/lib/rails/generators/active_record/migration/templates/{migration.rb → migration.rb.tt}
RENAMED
File without changes
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require "rails/generators/active_record"
|
2
4
|
|
3
5
|
module ActiveRecord
|
@@ -21,13 +23,11 @@ module ActiveRecord
|
|
21
23
|
end
|
22
24
|
|
23
25
|
def create_model_file
|
24
|
-
generate_application_record
|
25
26
|
template "model.rb", File.join("app/models", class_path, "#{file_name}.rb")
|
26
27
|
end
|
27
28
|
|
28
29
|
def create_module_file
|
29
30
|
return if regular_class_path.empty?
|
30
|
-
generate_application_record
|
31
31
|
template "module.rb", File.join("app/models", "#{class_path.join('/')}.rb") if behavior == :invoke
|
32
32
|
end
|
33
33
|
|
@@ -39,31 +39,10 @@ module ActiveRecord
|
|
39
39
|
attributes.select { |a| !a.reference? && a.has_index? }
|
40
40
|
end
|
41
41
|
|
42
|
-
# FIXME: Change this file to a symlink once RubyGems 2.5.0 is required.
|
43
|
-
def generate_application_record
|
44
|
-
if behavior == :invoke && !application_record_exist?
|
45
|
-
template "application_record.rb", application_record_file_name
|
46
|
-
end
|
47
|
-
end
|
48
|
-
|
49
42
|
# Used by the migration template to determine the parent name of the model
|
50
43
|
def parent_class_name
|
51
44
|
options[:parent] || "ApplicationRecord"
|
52
45
|
end
|
53
|
-
|
54
|
-
def application_record_exist?
|
55
|
-
file_exist = nil
|
56
|
-
in_root { file_exist = File.exist?(application_record_file_name) }
|
57
|
-
file_exist
|
58
|
-
end
|
59
|
-
|
60
|
-
def application_record_file_name
|
61
|
-
@application_record_file_name ||= if mountable_engine?
|
62
|
-
"app/models/#{namespaced_path}/application_record.rb"
|
63
|
-
else
|
64
|
-
"app/models/application_record.rb"
|
65
|
-
end
|
66
|
-
end
|
67
46
|
end
|
68
47
|
end
|
69
48
|
end
|
File without changes
|
File without changes
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require "rails/generators/named_base"
|
2
4
|
require "rails/generators/active_model"
|
3
5
|
require "rails/generators/active_record/migration"
|
@@ -10,7 +12,7 @@ module ActiveRecord
|
|
10
12
|
|
11
13
|
# Set the current directory as base for the inherited generators.
|
12
14
|
def self.base_root
|
13
|
-
|
15
|
+
__dir__
|
14
16
|
end
|
15
17
|
end
|
16
18
|
end
|
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: 5.
|
4
|
+
version: 5.2.0.rc1
|
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: 2018-01-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -16,42 +16,42 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - '='
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 5.
|
19
|
+
version: 5.2.0.rc1
|
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: 5.
|
26
|
+
version: 5.2.0.rc1
|
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: 5.
|
33
|
+
version: 5.2.0.rc1
|
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: 5.
|
40
|
+
version: 5.2.0.rc1
|
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: '
|
54
|
+
version: '9.0'
|
55
55
|
description: Databases on Rails. Build a persistent domain model by mapping database
|
56
56
|
tables to Ruby classes. Strong conventions for associations, validations, aggregations,
|
57
57
|
migrations, and testing come baked-in.
|
@@ -95,18 +95,9 @@ files:
|
|
95
95
|
- lib/active_record/associations/join_dependency/join_part.rb
|
96
96
|
- lib/active_record/associations/preloader.rb
|
97
97
|
- lib/active_record/associations/preloader/association.rb
|
98
|
-
- lib/active_record/associations/preloader/belongs_to.rb
|
99
|
-
- lib/active_record/associations/preloader/collection_association.rb
|
100
|
-
- lib/active_record/associations/preloader/has_many.rb
|
101
|
-
- lib/active_record/associations/preloader/has_many_through.rb
|
102
|
-
- lib/active_record/associations/preloader/has_one.rb
|
103
|
-
- lib/active_record/associations/preloader/has_one_through.rb
|
104
|
-
- lib/active_record/associations/preloader/singular_association.rb
|
105
98
|
- lib/active_record/associations/preloader/through_association.rb
|
106
99
|
- lib/active_record/associations/singular_association.rb
|
107
100
|
- lib/active_record/associations/through_association.rb
|
108
|
-
- lib/active_record/attribute.rb
|
109
|
-
- lib/active_record/attribute/user_provided_default.rb
|
110
101
|
- lib/active_record/attribute_assignment.rb
|
111
102
|
- lib/active_record/attribute_decorators.rb
|
112
103
|
- lib/active_record/attribute_methods.rb
|
@@ -118,10 +109,6 @@ files:
|
|
118
109
|
- lib/active_record/attribute_methods/serialization.rb
|
119
110
|
- lib/active_record/attribute_methods/time_zone_conversion.rb
|
120
111
|
- lib/active_record/attribute_methods/write.rb
|
121
|
-
- lib/active_record/attribute_mutation_tracker.rb
|
122
|
-
- lib/active_record/attribute_set.rb
|
123
|
-
- lib/active_record/attribute_set/builder.rb
|
124
|
-
- lib/active_record/attribute_set/yaml_encoder.rb
|
125
112
|
- lib/active_record/attributes.rb
|
126
113
|
- lib/active_record/autosave_association.rb
|
127
114
|
- lib/active_record/base.rb
|
@@ -169,7 +156,6 @@ files:
|
|
169
156
|
- lib/active_record/connection_adapters/postgresql/oid/enum.rb
|
170
157
|
- lib/active_record/connection_adapters/postgresql/oid/hstore.rb
|
171
158
|
- lib/active_record/connection_adapters/postgresql/oid/inet.rb
|
172
|
-
- lib/active_record/connection_adapters/postgresql/oid/json.rb
|
173
159
|
- lib/active_record/connection_adapters/postgresql/oid/jsonb.rb
|
174
160
|
- lib/active_record/connection_adapters/postgresql/oid/legacy_point.rb
|
175
161
|
- lib/active_record/connection_adapters/postgresql/oid/money.rb
|
@@ -236,7 +222,6 @@ files:
|
|
236
222
|
- lib/active_record/railties/console_sandbox.rb
|
237
223
|
- lib/active_record/railties/controller_runtime.rb
|
238
224
|
- lib/active_record/railties/databases.rake
|
239
|
-
- lib/active_record/railties/jdbcmysql_error.rb
|
240
225
|
- lib/active_record/readonly_attributes.rb
|
241
226
|
- lib/active_record/reflection.rb
|
242
227
|
- lib/active_record/relation.rb
|
@@ -249,10 +234,10 @@ files:
|
|
249
234
|
- lib/active_record/relation/merger.rb
|
250
235
|
- lib/active_record/relation/predicate_builder.rb
|
251
236
|
- lib/active_record/relation/predicate_builder/array_handler.rb
|
252
|
-
- lib/active_record/relation/predicate_builder/
|
237
|
+
- lib/active_record/relation/predicate_builder/association_query_value.rb
|
253
238
|
- lib/active_record/relation/predicate_builder/base_handler.rb
|
254
239
|
- lib/active_record/relation/predicate_builder/basic_object_handler.rb
|
255
|
-
- lib/active_record/relation/predicate_builder/
|
240
|
+
- lib/active_record/relation/predicate_builder/polymorphic_array_value.rb
|
256
241
|
- lib/active_record/relation/predicate_builder/range_handler.rb
|
257
242
|
- lib/active_record/relation/predicate_builder/relation_handler.rb
|
258
243
|
- lib/active_record/relation/query_attribute.rb
|
@@ -290,8 +275,8 @@ files:
|
|
290
275
|
- lib/active_record/type/date_time.rb
|
291
276
|
- lib/active_record/type/decimal_without_scale.rb
|
292
277
|
- lib/active_record/type/hash_lookup_type_map.rb
|
293
|
-
- lib/active_record/type/internal/abstract_json.rb
|
294
278
|
- lib/active_record/type/internal/timezone.rb
|
279
|
+
- lib/active_record/type/json.rb
|
295
280
|
- lib/active_record/type/serialized.rb
|
296
281
|
- lib/active_record/type/text.rb
|
297
282
|
- lib/active_record/type/time.rb
|
@@ -308,18 +293,21 @@ files:
|
|
308
293
|
- lib/active_record/validations/uniqueness.rb
|
309
294
|
- lib/active_record/version.rb
|
310
295
|
- lib/rails/generators/active_record.rb
|
296
|
+
- lib/rails/generators/active_record/application_record/application_record_generator.rb
|
297
|
+
- lib/rails/generators/active_record/application_record/templates/application_record.rb.tt
|
311
298
|
- lib/rails/generators/active_record/migration.rb
|
312
299
|
- lib/rails/generators/active_record/migration/migration_generator.rb
|
313
|
-
- lib/rails/generators/active_record/migration/templates/create_table_migration.rb
|
314
|
-
- lib/rails/generators/active_record/migration/templates/migration.rb
|
300
|
+
- lib/rails/generators/active_record/migration/templates/create_table_migration.rb.tt
|
301
|
+
- lib/rails/generators/active_record/migration/templates/migration.rb.tt
|
315
302
|
- lib/rails/generators/active_record/model/model_generator.rb
|
316
|
-
- lib/rails/generators/active_record/model/templates/
|
317
|
-
- lib/rails/generators/active_record/model/templates/
|
318
|
-
- lib/rails/generators/active_record/model/templates/module.rb
|
303
|
+
- lib/rails/generators/active_record/model/templates/model.rb.tt
|
304
|
+
- lib/rails/generators/active_record/model/templates/module.rb.tt
|
319
305
|
homepage: http://rubyonrails.org
|
320
306
|
licenses:
|
321
307
|
- MIT
|
322
|
-
metadata:
|
308
|
+
metadata:
|
309
|
+
source_code_uri: https://github.com/rails/rails/tree/v5.2.0.rc1/activerecord
|
310
|
+
changelog_uri: https://github.com/rails/rails/blob/v5.2.0.rc1/activerecord/CHANGELOG.md
|
323
311
|
post_install_message:
|
324
312
|
rdoc_options:
|
325
313
|
- "--main"
|
@@ -333,12 +321,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
333
321
|
version: 2.2.2
|
334
322
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
335
323
|
requirements:
|
336
|
-
- - "
|
324
|
+
- - ">"
|
337
325
|
- !ruby/object:Gem::Version
|
338
|
-
version:
|
326
|
+
version: 1.3.1
|
339
327
|
requirements: []
|
340
328
|
rubyforge_project:
|
341
|
-
rubygems_version: 2.
|
329
|
+
rubygems_version: 2.7.3
|
342
330
|
signing_key:
|
343
331
|
specification_version: 4
|
344
332
|
summary: Object-relational mapper framework (part of Rails).
|
@@ -1,15 +0,0 @@
|
|
1
|
-
module ActiveRecord
|
2
|
-
module Associations
|
3
|
-
class Preloader
|
4
|
-
class BelongsTo < SingularAssociation #:nodoc:
|
5
|
-
def association_key_name
|
6
|
-
reflection.options[:primary_key] || klass && klass.primary_key
|
7
|
-
end
|
8
|
-
|
9
|
-
def owner_key_name
|
10
|
-
reflection.foreign_key
|
11
|
-
end
|
12
|
-
end
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|
@@ -1,17 +0,0 @@
|
|
1
|
-
module ActiveRecord
|
2
|
-
module Associations
|
3
|
-
class Preloader
|
4
|
-
class CollectionAssociation < Association #:nodoc:
|
5
|
-
private
|
6
|
-
|
7
|
-
def preload(preloader)
|
8
|
-
associated_records_by_owner(preloader).each do |owner, records|
|
9
|
-
association = owner.association(reflection.name)
|
10
|
-
association.loaded!
|
11
|
-
association.target.concat(records)
|
12
|
-
end
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
@@ -1,15 +0,0 @@
|
|
1
|
-
module ActiveRecord
|
2
|
-
module Associations
|
3
|
-
class Preloader
|
4
|
-
class HasMany < CollectionAssociation #:nodoc:
|
5
|
-
def association_key_name
|
6
|
-
reflection.foreign_key
|
7
|
-
end
|
8
|
-
|
9
|
-
def owner_key_name
|
10
|
-
reflection.active_record_primary_key
|
11
|
-
end
|
12
|
-
end
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|
@@ -1,19 +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(preloader)
|
8
|
-
records_by_owner = super
|
9
|
-
|
10
|
-
if reflection_scope.distinct_value
|
11
|
-
records_by_owner.each_value(&:uniq!)
|
12
|
-
end
|
13
|
-
|
14
|
-
records_by_owner
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
@@ -1,15 +0,0 @@
|
|
1
|
-
module ActiveRecord
|
2
|
-
module Associations
|
3
|
-
class Preloader
|
4
|
-
class HasOne < SingularAssociation #:nodoc:
|
5
|
-
def association_key_name
|
6
|
-
reflection.foreign_key
|
7
|
-
end
|
8
|
-
|
9
|
-
def owner_key_name
|
10
|
-
reflection.active_record_primary_key
|
11
|
-
end
|
12
|
-
end
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|
@@ -1,18 +0,0 @@
|
|
1
|
-
module ActiveRecord
|
2
|
-
module Associations
|
3
|
-
class Preloader
|
4
|
-
class SingularAssociation < Association #:nodoc:
|
5
|
-
private
|
6
|
-
|
7
|
-
def preload(preloader)
|
8
|
-
associated_records_by_owner(preloader).each do |owner, associated_records|
|
9
|
-
record = associated_records.first
|
10
|
-
|
11
|
-
association = owner.association(reflection.name)
|
12
|
-
association.target = record
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|