activerecord 5.1.0 → 5.2.3
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 +596 -450
- data/MIT-LICENSE +1 -1
- data/README.rdoc +5 -5
- data/examples/performance.rb +2 -0
- data/examples/simple.rb +2 -0
- data/lib/active_record.rb +11 -4
- data/lib/active_record/aggregations.rb +6 -5
- data/lib/active_record/association_relation.rb +7 -5
- data/lib/active_record/associations.rb +77 -85
- data/lib/active_record/associations/alias_tracker.rb +23 -32
- data/lib/active_record/associations/association.rb +49 -35
- data/lib/active_record/associations/association_scope.rb +55 -55
- data/lib/active_record/associations/belongs_to_association.rb +30 -11
- data/lib/active_record/associations/belongs_to_polymorphic_association.rb +8 -8
- data/lib/active_record/associations/builder/association.rb +4 -7
- data/lib/active_record/associations/builder/belongs_to.rb +21 -8
- 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 +66 -53
- data/lib/active_record/associations/collection_proxy.rb +30 -73
- data/lib/active_record/associations/foreign_association.rb +2 -0
- data/lib/active_record/associations/has_many_association.rb +13 -2
- data/lib/active_record/associations/has_many_through_association.rb +37 -19
- data/lib/active_record/associations/has_one_association.rb +14 -1
- data/lib/active_record/associations/has_one_through_association.rb +13 -8
- data/lib/active_record/associations/join_dependency.rb +52 -96
- data/lib/active_record/associations/join_dependency/join_association.rb +22 -75
- data/lib/active_record/associations/join_dependency/join_base.rb +9 -8
- data/lib/active_record/associations/join_dependency/join_part.rb +9 -9
- data/lib/active_record/associations/preloader.rb +17 -37
- 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/singular_association.rb +14 -16
- data/lib/active_record/associations/through_association.rb +27 -12
- data/lib/active_record/attribute_assignment.rb +2 -5
- data/lib/active_record/attribute_decorators.rb +3 -2
- data/lib/active_record/attribute_methods.rb +65 -24
- data/lib/active_record/attribute_methods/before_type_cast.rb +2 -0
- data/lib/active_record/attribute_methods/dirty.rb +33 -216
- 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 +9 -3
- 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/attributes.rb +7 -6
- data/lib/active_record/autosave_association.rb +15 -13
- data/lib/active_record/base.rb +2 -0
- data/lib/active_record/callbacks.rb +12 -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 +15 -11
- data/lib/active_record/connection_adapters/abstract/connection_pool.rb +120 -39
- data/lib/active_record/connection_adapters/abstract/database_limits.rb +7 -0
- data/lib/active_record/connection_adapters/abstract/database_statements.rb +192 -37
- data/lib/active_record/connection_adapters/abstract/query_cache.rb +13 -2
- data/lib/active_record/connection_adapters/abstract/quoting.rb +15 -25
- 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 +65 -7
- data/lib/active_record/connection_adapters/abstract/schema_dumper.rb +31 -53
- data/lib/active_record/connection_adapters/abstract/schema_statements.rb +158 -87
- data/lib/active_record/connection_adapters/abstract/transaction.rb +66 -21
- data/lib/active_record/connection_adapters/abstract_adapter.rb +86 -98
- data/lib/active_record/connection_adapters/abstract_mysql_adapter.rb +126 -189
- 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 +13 -2
- data/lib/active_record/connection_adapters/mysql/column.rb +2 -0
- data/lib/active_record/connection_adapters/mysql/database_statements.rb +45 -15
- 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.rb +3 -1
- data/lib/active_record/connection_adapters/postgresql/oid/array.rb +13 -1
- 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.rb +23 -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 +8 -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/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 +50 -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 +258 -129
- data/lib/active_record/connection_adapters/postgresql/type_metadata.rb +2 -0
- data/lib/active_record/connection_adapters/postgresql/utils.rb +3 -1
- data/lib/active_record/connection_adapters/postgresql_adapter.rb +75 -87
- 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 +24 -1
- 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 +75 -1
- data/lib/active_record/connection_adapters/sqlite3_adapter.rb +90 -96
- 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 +41 -61
- data/lib/active_record/counter_cache.rb +20 -15
- data/lib/active_record/define_callbacks.rb +5 -3
- data/lib/active_record/dynamic_matchers.rb +9 -9
- data/lib/active_record/enum.rb +18 -13
- data/lib/active_record/errors.rb +60 -15
- 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 +49 -19
- 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 +30 -42
- data/lib/active_record/locking/pessimistic.rb +10 -7
- data/lib/active_record/log_subscriber.rb +46 -4
- data/lib/active_record/migration.rb +189 -139
- data/lib/active_record/migration/command_recorder.rb +11 -9
- data/lib/active_record/migration/compatibility.rb +81 -29
- data/lib/active_record/migration/join_table.rb +2 -0
- data/lib/active_record/model_schema.rb +74 -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 +199 -54
- data/lib/active_record/query_cache.rb +8 -10
- data/lib/active_record/querying.rb +5 -3
- data/lib/active_record/railtie.rb +62 -6
- 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 +48 -38
- data/lib/active_record/readonly_attributes.rb +3 -2
- data/lib/active_record/reflection.rb +137 -207
- data/lib/active_record/relation.rb +132 -207
- data/lib/active_record/relation/batches.rb +32 -17
- data/lib/active_record/relation/batches/batch_enumerator.rb +2 -0
- data/lib/active_record/relation/calculations.rb +66 -25
- data/lib/active_record/relation/delegation.rb +45 -29
- data/lib/active_record/relation/finder_methods.rb +76 -85
- data/lib/active_record/relation/from_clause.rb +2 -8
- data/lib/active_record/relation/merger.rb +53 -23
- data/lib/active_record/relation/predicate_builder.rb +60 -79
- 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 +56 -0
- data/lib/active_record/relation/predicate_builder/range_handler.rb +26 -9
- data/lib/active_record/relation/predicate_builder/relation_handler.rb +6 -0
- data/lib/active_record/relation/query_attribute.rb +28 -2
- data/lib/active_record/relation/query_methods.rb +135 -103
- data/lib/active_record/relation/record_fetch_warning.rb +2 -0
- data/lib/active_record/relation/spawn_methods.rb +4 -2
- 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/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.rb +12 -10
- data/lib/active_record/scoping/default.rb +10 -7
- data/lib/active_record/scoping/named.rb +40 -12
- 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 +38 -26
- 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 +13 -6
- data/lib/active_record/touch_later.rb +2 -0
- data/lib/active_record/transactions.rb +32 -27
- data/lib/active_record/translation.rb +2 -0
- data/lib/active_record/type.rb +4 -1
- 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 +6 -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_caster.rb +2 -0
- data/lib/active_record/type_caster/connection.rb +2 -0
- data/lib/active_record/type_caster/map.rb +3 -1
- data/lib/active_record/validations.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 +36 -6
- data/lib/active_record/version.rb +2 -0
- data/lib/rails/generators/active_record.rb +3 -1
- 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.rb +2 -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/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
- metadata +24 -36
- 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.rb +0 -240
- data/lib/active_record/attribute/user_provided_default.rb +0 -30
- data/lib/active_record/attribute_mutation_tracker.rb +0 -113
- data/lib/active_record/attribute_set.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/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)
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ActiveRecord
|
4
|
+
module Type
|
5
|
+
class Json < ActiveModel::Type::Value
|
6
|
+
include ActiveModel::Type::Helpers::Mutable
|
7
|
+
|
8
|
+
def type
|
9
|
+
:json
|
10
|
+
end
|
11
|
+
|
12
|
+
def deserialize(value)
|
13
|
+
return value unless value.is_a?(::String)
|
14
|
+
ActiveSupport::JSON.decode(value) rescue nil
|
15
|
+
end
|
16
|
+
|
17
|
+
def serialize(value)
|
18
|
+
ActiveSupport::JSON.encode(value) unless value.nil?
|
19
|
+
end
|
20
|
+
|
21
|
+
def changed_in_place?(raw_old_value, new_value)
|
22
|
+
deserialize(raw_old_value) != new_value
|
23
|
+
end
|
24
|
+
|
25
|
+
def accessor
|
26
|
+
ActiveRecord::Store::StringKeyedHashAccessor
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module ActiveRecord
|
2
4
|
module Type
|
3
5
|
class Serialized < DelegateClass(ActiveModel::Type::Value) # :nodoc:
|
@@ -49,6 +51,10 @@ module ActiveRecord
|
|
49
51
|
end
|
50
52
|
end
|
51
53
|
|
54
|
+
def force_equality?(value)
|
55
|
+
coder.respond_to?(:object_class) && value.is_a?(coder.object_class)
|
56
|
+
end
|
57
|
+
|
52
58
|
private
|
53
59
|
|
54
60
|
def default_value?(value)
|
@@ -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
|
@@ -17,7 +23,7 @@ module ActiveRecord
|
|
17
23
|
relation = build_relation(finder_class, attribute, value)
|
18
24
|
if record.persisted?
|
19
25
|
if finder_class.primary_key
|
20
|
-
relation = relation.where.not(finder_class.primary_key => record.id_in_database
|
26
|
+
relation = relation.where.not(finder_class.primary_key => record.id_in_database)
|
21
27
|
else
|
22
28
|
raise UnknownPrimaryKey.new(finder_class, "Can not validate uniqueness for persisted record without primary key.")
|
23
29
|
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
|
@@ -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
|
@@ -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
|
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.3
|
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: 2019-03-28 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.3
|
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.3
|
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.3
|
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.3
|
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
|
@@ -164,12 +151,12 @@ files:
|
|
164
151
|
- lib/active_record/connection_adapters/postgresql/oid/bit_varying.rb
|
165
152
|
- lib/active_record/connection_adapters/postgresql/oid/bytea.rb
|
166
153
|
- lib/active_record/connection_adapters/postgresql/oid/cidr.rb
|
154
|
+
- lib/active_record/connection_adapters/postgresql/oid/date.rb
|
167
155
|
- lib/active_record/connection_adapters/postgresql/oid/date_time.rb
|
168
156
|
- lib/active_record/connection_adapters/postgresql/oid/decimal.rb
|
169
157
|
- lib/active_record/connection_adapters/postgresql/oid/enum.rb
|
170
158
|
- lib/active_record/connection_adapters/postgresql/oid/hstore.rb
|
171
159
|
- lib/active_record/connection_adapters/postgresql/oid/inet.rb
|
172
|
-
- lib/active_record/connection_adapters/postgresql/oid/json.rb
|
173
160
|
- lib/active_record/connection_adapters/postgresql/oid/jsonb.rb
|
174
161
|
- lib/active_record/connection_adapters/postgresql/oid/legacy_point.rb
|
175
162
|
- lib/active_record/connection_adapters/postgresql/oid/money.rb
|
@@ -236,7 +223,6 @@ files:
|
|
236
223
|
- lib/active_record/railties/console_sandbox.rb
|
237
224
|
- lib/active_record/railties/controller_runtime.rb
|
238
225
|
- lib/active_record/railties/databases.rake
|
239
|
-
- lib/active_record/railties/jdbcmysql_error.rb
|
240
226
|
- lib/active_record/readonly_attributes.rb
|
241
227
|
- lib/active_record/reflection.rb
|
242
228
|
- lib/active_record/relation.rb
|
@@ -249,10 +235,10 @@ files:
|
|
249
235
|
- lib/active_record/relation/merger.rb
|
250
236
|
- lib/active_record/relation/predicate_builder.rb
|
251
237
|
- lib/active_record/relation/predicate_builder/array_handler.rb
|
252
|
-
- lib/active_record/relation/predicate_builder/
|
238
|
+
- lib/active_record/relation/predicate_builder/association_query_value.rb
|
253
239
|
- lib/active_record/relation/predicate_builder/base_handler.rb
|
254
240
|
- lib/active_record/relation/predicate_builder/basic_object_handler.rb
|
255
|
-
- lib/active_record/relation/predicate_builder/
|
241
|
+
- lib/active_record/relation/predicate_builder/polymorphic_array_value.rb
|
256
242
|
- lib/active_record/relation/predicate_builder/range_handler.rb
|
257
243
|
- lib/active_record/relation/predicate_builder/relation_handler.rb
|
258
244
|
- lib/active_record/relation/query_attribute.rb
|
@@ -290,8 +276,8 @@ files:
|
|
290
276
|
- lib/active_record/type/date_time.rb
|
291
277
|
- lib/active_record/type/decimal_without_scale.rb
|
292
278
|
- lib/active_record/type/hash_lookup_type_map.rb
|
293
|
-
- lib/active_record/type/internal/abstract_json.rb
|
294
279
|
- lib/active_record/type/internal/timezone.rb
|
280
|
+
- lib/active_record/type/json.rb
|
295
281
|
- lib/active_record/type/serialized.rb
|
296
282
|
- lib/active_record/type/text.rb
|
297
283
|
- lib/active_record/type/time.rb
|
@@ -308,18 +294,21 @@ files:
|
|
308
294
|
- lib/active_record/validations/uniqueness.rb
|
309
295
|
- lib/active_record/version.rb
|
310
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
|
311
299
|
- lib/rails/generators/active_record/migration.rb
|
312
300
|
- 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
|
301
|
+
- lib/rails/generators/active_record/migration/templates/create_table_migration.rb.tt
|
302
|
+
- lib/rails/generators/active_record/migration/templates/migration.rb.tt
|
315
303
|
- 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
|
304
|
+
- lib/rails/generators/active_record/model/templates/model.rb.tt
|
305
|
+
- lib/rails/generators/active_record/model/templates/module.rb.tt
|
319
306
|
homepage: http://rubyonrails.org
|
320
307
|
licenses:
|
321
308
|
- MIT
|
322
|
-
metadata:
|
309
|
+
metadata:
|
310
|
+
source_code_uri: https://github.com/rails/rails/tree/v5.2.3/activerecord
|
311
|
+
changelog_uri: https://github.com/rails/rails/blob/v5.2.3/activerecord/CHANGELOG.md
|
323
312
|
post_install_message:
|
324
313
|
rdoc_options:
|
325
314
|
- "--main"
|
@@ -337,8 +326,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
337
326
|
- !ruby/object:Gem::Version
|
338
327
|
version: '0'
|
339
328
|
requirements: []
|
340
|
-
|
341
|
-
rubygems_version: 2.6.11
|
329
|
+
rubygems_version: 3.0.1
|
342
330
|
signing_key:
|
343
331
|
specification_version: 4
|
344
332
|
summary: Object-relational mapper framework (part of Rails).
|