activerecord 5.0.1 → 5.0.2.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 +4 -4
- data/CHANGELOG.md +45 -0
- data/lib/active_record.rb +2 -1
- data/lib/active_record/associations/collection_association.rb +16 -9
- data/lib/active_record/associations/has_many_through_association.rb +6 -8
- data/lib/active_record/attribute_methods/read.rb +1 -1
- data/lib/active_record/connection_adapters/abstract/connection_pool.rb +1 -1
- data/lib/active_record/connection_adapters/abstract/quoting.rb +1 -0
- data/lib/active_record/connection_adapters/abstract/schema_statements.rb +28 -20
- data/lib/active_record/connection_adapters/abstract_mysql_adapter.rb +3 -2
- data/lib/active_record/connection_adapters/postgresql/oid/array.rb +12 -13
- data/lib/active_record/connection_adapters/postgresql/oid/hstore.rb +8 -0
- data/lib/active_record/connection_adapters/postgresql/quoting.rb +29 -0
- data/lib/active_record/core.rb +3 -3
- data/lib/active_record/enum.rb +2 -0
- data/lib/active_record/fixtures.rb +5 -5
- data/lib/active_record/gem_version.rb +2 -2
- data/lib/active_record/log_subscriber.rb +1 -2
- data/lib/active_record/migration.rb +4 -2
- data/lib/active_record/model_schema.rb +1 -0
- data/lib/active_record/persistence.rb +8 -8
- data/lib/active_record/reflection.rb +2 -2
- data/lib/active_record/relation/delegation.rb +1 -0
- data/lib/active_record/relation/finder_methods.rb +2 -2
- data/lib/active_record/serialization.rb +1 -1
- data/lib/rails/generators/active_record/migration/migration_generator.rb +9 -1
- data/lib/rails/generators/active_record/model/model_generator.rb +9 -1
- metadata +9 -10
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 03c9dc6fffc731779f3684560496ffb8655ede82
|
4
|
+
data.tar.gz: c76575e2fad497944d4634c20888466457500547
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c108a0f711778b27f7cc293e8ac9ac4144f43aa0ac151cb09d8ac08a67d6be250a9088534c58d9629a8a017395d1ba48c7f1f618c41a4a4a622ee2776727bba7
|
7
|
+
data.tar.gz: 9afced7225ac120089ee47ef6e20562c72a3699a4a71bb164b100fb2c24fe95468158a8f0737790bbff018064107f2607b70a9b8637dcd11318835e094c6ebab
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,48 @@
|
|
1
|
+
## Rails 5.0.2.rc1 (February 24, 2017) ##
|
2
|
+
|
3
|
+
* Fix `wait_timeout` to configurable for mysql2 adapter.
|
4
|
+
|
5
|
+
Fixes #26556.
|
6
|
+
|
7
|
+
*Ryuta Kamizono*
|
8
|
+
|
9
|
+
* Make `table_name=` reset current statement cache,
|
10
|
+
so queries are not run against the previous table name.
|
11
|
+
|
12
|
+
*namusyaka*
|
13
|
+
|
14
|
+
* Allow ActiveRecord::Base#as_json to be passed a frozen Hash.
|
15
|
+
|
16
|
+
*Isaac Betesh*
|
17
|
+
|
18
|
+
* Fix inspection behavior when the :id column is not primary key.
|
19
|
+
|
20
|
+
*namusyaka*
|
21
|
+
|
22
|
+
* Fix `association_primary_key_type` for reflections with symbol primary key
|
23
|
+
|
24
|
+
Fixes #27864
|
25
|
+
|
26
|
+
*Daniel Colson*
|
27
|
+
|
28
|
+
* Place generated migrations into the path set by `config.paths["db/migrate"]`
|
29
|
+
|
30
|
+
*Kevin Glowacz*
|
31
|
+
|
32
|
+
* Compare deserialized values for `PostgreSQL::OID::Hstore` types when
|
33
|
+
calling `ActiveRecord::Dirty#changed_in_place?`
|
34
|
+
|
35
|
+
Fixes #27502.
|
36
|
+
|
37
|
+
*Jon Moss*
|
38
|
+
|
39
|
+
* Respect precision option for arrays of timestamps.
|
40
|
+
|
41
|
+
Fixes #27514.
|
42
|
+
|
43
|
+
*Sean Griffin*
|
44
|
+
|
45
|
+
|
1
46
|
## Rails 5.0.1 (December 21, 2016) ##
|
2
47
|
|
3
48
|
* No changes.
|
data/lib/active_record.rb
CHANGED
@@ -44,7 +44,6 @@ module ActiveRecord
|
|
44
44
|
autoload :Explain
|
45
45
|
autoload :Inheritance
|
46
46
|
autoload :Integration
|
47
|
-
autoload :LegacyYamlAdapter
|
48
47
|
autoload :Migration
|
49
48
|
autoload :Migrator, 'active_record/migration'
|
50
49
|
autoload :ModelSchema
|
@@ -85,6 +84,8 @@ module ActiveRecord
|
|
85
84
|
autoload :AttributeMethods
|
86
85
|
autoload :AutosaveAssociation
|
87
86
|
|
87
|
+
autoload :LegacyYamlAdapter
|
88
|
+
|
88
89
|
autoload :Relation
|
89
90
|
autoload :AssociationRelation
|
90
91
|
autoload :NullRelation
|
@@ -430,12 +430,23 @@ module ActiveRecord
|
|
430
430
|
def replace_on_target(record, index, skip_callbacks)
|
431
431
|
callback(:before_add, record) unless skip_callbacks
|
432
432
|
|
433
|
-
|
433
|
+
begin
|
434
|
+
if index
|
435
|
+
record_was = target[index]
|
436
|
+
target[index] = record
|
437
|
+
else
|
438
|
+
target << record
|
439
|
+
end
|
434
440
|
|
435
|
-
|
436
|
-
|
437
|
-
|
438
|
-
|
441
|
+
yield(record) if block_given?
|
442
|
+
rescue
|
443
|
+
if index
|
444
|
+
target[index] = record_was
|
445
|
+
else
|
446
|
+
target.delete(record)
|
447
|
+
end
|
448
|
+
|
449
|
+
raise
|
439
450
|
end
|
440
451
|
|
441
452
|
callback(:after_add, record) unless skip_callbacks
|
@@ -658,10 +669,6 @@ module ActiveRecord
|
|
658
669
|
set_inverse_instance record if record.is_a? ActiveRecord::Base
|
659
670
|
end
|
660
671
|
end
|
661
|
-
|
662
|
-
def append_record(record)
|
663
|
-
@target << record unless @target.include?(record)
|
664
|
-
end
|
665
672
|
end
|
666
673
|
end
|
667
674
|
end
|
@@ -38,10 +38,12 @@ module ActiveRecord
|
|
38
38
|
def insert_record(record, validate = true, raise = false)
|
39
39
|
ensure_not_nested
|
40
40
|
|
41
|
-
if
|
42
|
-
|
43
|
-
|
44
|
-
|
41
|
+
if record.new_record? || record.changed?
|
42
|
+
if raise
|
43
|
+
record.save!(validate: validate)
|
44
|
+
else
|
45
|
+
return unless record.save(validate: validate)
|
46
|
+
end
|
45
47
|
end
|
46
48
|
|
47
49
|
save_through_record(record)
|
@@ -203,10 +205,6 @@ module ActiveRecord
|
|
203
205
|
def invertible_for?(record)
|
204
206
|
false
|
205
207
|
end
|
206
|
-
|
207
|
-
def append_record(record)
|
208
|
-
@target << record
|
209
|
-
end
|
210
208
|
end
|
211
209
|
end
|
212
210
|
end
|
@@ -49,7 +49,7 @@ module ActiveRecord
|
|
49
49
|
# to a date object, like Date.new(2004, 12, 12)).
|
50
50
|
def read_attribute(attr_name, &block)
|
51
51
|
name = attr_name.to_s
|
52
|
-
name = self.class.primary_key if name ==
|
52
|
+
name = self.class.primary_key if name == "id".freeze && self.class.primary_key
|
53
53
|
_read_attribute(name, &block)
|
54
54
|
end
|
55
55
|
|
@@ -935,7 +935,7 @@ module ActiveRecord
|
|
935
935
|
end
|
936
936
|
|
937
937
|
def pool_from_any_process_for(spec_name)
|
938
|
-
owner_to_pool = @owner_to_pool.values.find { |v| v[spec_name] }
|
938
|
+
owner_to_pool = @owner_to_pool.values.reverse.find { |v| v[spec_name] }
|
939
939
|
owner_to_pool && owner_to_pool[spec_name]
|
940
940
|
end
|
941
941
|
end
|
@@ -762,7 +762,7 @@ module ActiveRecord
|
|
762
762
|
raise ArgumentError, "You must specify the index name"
|
763
763
|
end
|
764
764
|
else
|
765
|
-
index_name(table_name,
|
765
|
+
index_name(table_name, index_name_options(options))
|
766
766
|
end
|
767
767
|
end
|
768
768
|
|
@@ -990,17 +990,15 @@ module ActiveRecord
|
|
990
990
|
end
|
991
991
|
|
992
992
|
def insert_versions_sql(versions) # :nodoc:
|
993
|
-
sm_table = ActiveRecord::Migrator.schema_migrations_table_name
|
993
|
+
sm_table = quote_table_name(ActiveRecord::Migrator.schema_migrations_table_name)
|
994
994
|
|
995
|
-
if
|
995
|
+
if versions.is_a?(Array)
|
996
996
|
sql = "INSERT INTO #{sm_table} (version) VALUES\n"
|
997
|
-
sql << versions.map {|v| "(
|
997
|
+
sql << versions.map { |v| "(#{quote(v)})" }.join(",\n")
|
998
998
|
sql << ";\n\n"
|
999
999
|
sql
|
1000
1000
|
else
|
1001
|
-
|
1002
|
-
"INSERT INTO #{sm_table} (version) VALUES ('#{version}');"
|
1003
|
-
}.join "\n\n"
|
1001
|
+
"INSERT INTO #{sm_table} (version) VALUES (#{quote(versions)});"
|
1004
1002
|
end
|
1005
1003
|
end
|
1006
1004
|
|
@@ -1030,7 +1028,7 @@ module ActiveRecord
|
|
1030
1028
|
end
|
1031
1029
|
|
1032
1030
|
unless migrated.include?(version)
|
1033
|
-
execute "INSERT INTO #{sm_table} (version) VALUES (
|
1031
|
+
execute "INSERT INTO #{sm_table} (version) VALUES (#{quote(version)})"
|
1034
1032
|
end
|
1035
1033
|
|
1036
1034
|
inserting = (versions - migrated).select {|v| v < version}
|
@@ -1038,7 +1036,13 @@ module ActiveRecord
|
|
1038
1036
|
if (duplicate = inserting.detect {|v| inserting.count(v) > 1})
|
1039
1037
|
raise "Duplicate migration #{duplicate}. Please renumber your migrations to resolve the conflict."
|
1040
1038
|
end
|
1041
|
-
|
1039
|
+
if supports_multi_insert?
|
1040
|
+
execute insert_versions_sql(inserting)
|
1041
|
+
else
|
1042
|
+
inserting.each do |v|
|
1043
|
+
execute insert_versions_sql(v)
|
1044
|
+
end
|
1045
|
+
end
|
1042
1046
|
end
|
1043
1047
|
end
|
1044
1048
|
|
@@ -1112,18 +1116,14 @@ module ActiveRecord
|
|
1112
1116
|
end
|
1113
1117
|
|
1114
1118
|
def add_index_options(table_name, column_name, comment: nil, **options) # :nodoc:
|
1115
|
-
|
1116
|
-
column_names = column_name
|
1117
|
-
else
|
1118
|
-
column_names = Array(column_name)
|
1119
|
-
end
|
1119
|
+
column_names = index_column_names(column_name)
|
1120
1120
|
|
1121
1121
|
options.assert_valid_keys(:unique, :order, :name, :where, :length, :internal, :using, :algorithm, :type)
|
1122
1122
|
|
1123
1123
|
index_type = options[:type].to_s if options.key?(:type)
|
1124
1124
|
index_type ||= options[:unique] ? "UNIQUE" : ""
|
1125
1125
|
index_name = options[:name].to_s if options.key?(:name)
|
1126
|
-
index_name ||= index_name(table_name,
|
1126
|
+
index_name ||= index_name(table_name, column_names)
|
1127
1127
|
max_index_length = options.fetch(:internal, false) ? index_name_length : allowed_index_name_length
|
1128
1128
|
|
1129
1129
|
if options.key?(:algorithm)
|
@@ -1206,13 +1206,13 @@ module ActiveRecord
|
|
1206
1206
|
|
1207
1207
|
if options.is_a?(Hash)
|
1208
1208
|
checks << lambda { |i| i.name == options[:name].to_s } if options.key?(:name)
|
1209
|
-
column_names =
|
1209
|
+
column_names = index_column_names(options[:column])
|
1210
1210
|
else
|
1211
|
-
column_names =
|
1211
|
+
column_names = index_column_names(options)
|
1212
1212
|
end
|
1213
1213
|
|
1214
|
-
if column_names.
|
1215
|
-
checks << lambda { |i| i.columns
|
1214
|
+
if column_names.present?
|
1215
|
+
checks << lambda { |i| index_name(table_name, i.columns) == index_name(table_name, column_names) }
|
1216
1216
|
end
|
1217
1217
|
|
1218
1218
|
raise ArgumentError, "No name or columns specified" if checks.none?
|
@@ -1260,8 +1260,16 @@ module ActiveRecord
|
|
1260
1260
|
AlterTable.new create_table_definition(name)
|
1261
1261
|
end
|
1262
1262
|
|
1263
|
+
def index_column_names(column_names)
|
1264
|
+
if column_names.is_a?(String) && /\W/ === column_names
|
1265
|
+
column_names
|
1266
|
+
else
|
1267
|
+
Array(column_names)
|
1268
|
+
end
|
1269
|
+
end
|
1270
|
+
|
1263
1271
|
def index_name_options(column_names) # :nodoc:
|
1264
|
-
if column_names.is_a?(String)
|
1272
|
+
if column_names.is_a?(String) && /\W/ === column_names
|
1265
1273
|
column_names = column_names.scan(/\w+/).join('_')
|
1266
1274
|
end
|
1267
1275
|
|
@@ -530,6 +530,7 @@ module ActiveRecord
|
|
530
530
|
WHERE fk.referenced_column_name IS NOT NULL
|
531
531
|
AND fk.table_schema = #{quote(schema)}
|
532
532
|
AND fk.table_name = #{quote(name)}
|
533
|
+
AND rc.table_name = #{quote(name)}
|
533
534
|
SQL
|
534
535
|
|
535
536
|
fk_info.map do |row|
|
@@ -835,9 +836,9 @@ module ActiveRecord
|
|
835
836
|
variables['sql_auto_is_null'] = 0
|
836
837
|
|
837
838
|
# Increase timeout so the server doesn't disconnect us.
|
838
|
-
wait_timeout = @config[:wait_timeout]
|
839
|
+
wait_timeout = self.class.type_cast_config_to_integer(@config[:wait_timeout])
|
839
840
|
wait_timeout = 2147483 unless wait_timeout.is_a?(Integer)
|
840
|
-
variables[
|
841
|
+
variables["wait_timeout"] = wait_timeout
|
841
842
|
|
842
843
|
defaults = [':default', :default].to_set
|
843
844
|
|
@@ -5,6 +5,8 @@ module ActiveRecord
|
|
5
5
|
class Array < Type::Value # :nodoc:
|
6
6
|
include Type::Helpers::Mutable
|
7
7
|
|
8
|
+
Data = Struct.new(:encoder, :values) # :nodoc:
|
9
|
+
|
8
10
|
attr_reader :subtype, :delimiter
|
9
11
|
delegate :type, :user_input_in_time_zone, :limit, to: :subtype
|
10
12
|
|
@@ -17,8 +19,11 @@ module ActiveRecord
|
|
17
19
|
end
|
18
20
|
|
19
21
|
def deserialize(value)
|
20
|
-
|
22
|
+
case value
|
23
|
+
when ::String
|
21
24
|
type_cast_array(@pg_decoder.decode(value), :deserialize)
|
25
|
+
when Data
|
26
|
+
deserialize(value.values)
|
22
27
|
else
|
23
28
|
super
|
24
29
|
end
|
@@ -33,11 +38,8 @@ module ActiveRecord
|
|
33
38
|
|
34
39
|
def serialize(value)
|
35
40
|
if value.is_a?(::Array)
|
36
|
-
|
37
|
-
|
38
|
-
result.force_encoding(encoding)
|
39
|
-
end
|
40
|
-
result
|
41
|
+
casted_values = type_cast_array(value, :serialize)
|
42
|
+
Data.new(@pg_encoder, casted_values)
|
41
43
|
else
|
42
44
|
super
|
43
45
|
end
|
@@ -58,6 +60,10 @@ module ActiveRecord
|
|
58
60
|
value.map(&block)
|
59
61
|
end
|
60
62
|
|
63
|
+
def changed_in_place?(raw_old_value, new_value)
|
64
|
+
deserialize(raw_old_value) != new_value
|
65
|
+
end
|
66
|
+
|
61
67
|
private
|
62
68
|
|
63
69
|
def type_cast_array(value, method)
|
@@ -67,13 +73,6 @@ module ActiveRecord
|
|
67
73
|
@subtype.public_send(method, value)
|
68
74
|
end
|
69
75
|
end
|
70
|
-
|
71
|
-
def determine_encoding_of_strings(value)
|
72
|
-
case value
|
73
|
-
when ::Array then determine_encoding_of_strings(value.first)
|
74
|
-
when ::String then value.encoding
|
75
|
-
end
|
76
|
-
end
|
77
76
|
end
|
78
77
|
end
|
79
78
|
end
|
@@ -35,6 +35,14 @@ module ActiveRecord
|
|
35
35
|
ActiveRecord::Store::StringKeyedHashAccessor
|
36
36
|
end
|
37
37
|
|
38
|
+
# Will compare the Hash equivalents of +raw_old_value+ and +new_value+.
|
39
|
+
# By comparing hashes, this avoids an edge case where the order of
|
40
|
+
# the keys change between the two hashes, and they would not be marked
|
41
|
+
# as equal.
|
42
|
+
def changed_in_place?(raw_old_value, new_value)
|
43
|
+
deserialize(raw_old_value) != new_value
|
44
|
+
end
|
45
|
+
|
38
46
|
private
|
39
47
|
|
40
48
|
HstorePair = begin
|
@@ -92,6 +92,8 @@ module ActiveRecord
|
|
92
92
|
else
|
93
93
|
super
|
94
94
|
end
|
95
|
+
when OID::Array::Data
|
96
|
+
_quote(encode_array(value))
|
95
97
|
else
|
96
98
|
super
|
97
99
|
end
|
@@ -106,10 +108,37 @@ module ActiveRecord
|
|
106
108
|
{ value: value.to_s, format: 1 }
|
107
109
|
when OID::Xml::Data, OID::Bit::Data
|
108
110
|
value.to_s
|
111
|
+
when OID::Array::Data
|
112
|
+
encode_array(value)
|
109
113
|
else
|
110
114
|
super
|
111
115
|
end
|
112
116
|
end
|
117
|
+
|
118
|
+
def encode_array(array_data)
|
119
|
+
encoder = array_data.encoder
|
120
|
+
values = type_cast_array(array_data.values)
|
121
|
+
|
122
|
+
result = encoder.encode(values)
|
123
|
+
if encoding = determine_encoding_of_strings_in_array(values)
|
124
|
+
result.force_encoding(encoding)
|
125
|
+
end
|
126
|
+
result
|
127
|
+
end
|
128
|
+
|
129
|
+
def determine_encoding_of_strings_in_array(value)
|
130
|
+
case value
|
131
|
+
when ::Array then determine_encoding_of_strings_in_array(value.first)
|
132
|
+
when ::String then value.encoding
|
133
|
+
end
|
134
|
+
end
|
135
|
+
|
136
|
+
def type_cast_array(values)
|
137
|
+
case values
|
138
|
+
when ::Array then values.map { |item| type_cast_array(item) }
|
139
|
+
else _type_cast(values)
|
140
|
+
end
|
141
|
+
end
|
113
142
|
end
|
114
143
|
end
|
115
144
|
end
|
data/lib/active_record/core.rb
CHANGED
@@ -180,12 +180,12 @@ module ActiveRecord
|
|
180
180
|
end
|
181
181
|
|
182
182
|
def find_by(*args) # :nodoc:
|
183
|
-
return super if scope_attributes? ||
|
183
|
+
return super if scope_attributes? || reflect_on_all_aggregations.any?
|
184
184
|
|
185
185
|
hash = args.first
|
186
186
|
|
187
|
-
return super if hash.values.any? { |v|
|
188
|
-
v.nil? || Array === v || Hash === v || Relation === v
|
187
|
+
return super if !(Hash === hash) || hash.values.any? { |v|
|
188
|
+
v.nil? || Array === v || Hash === v || Relation === v || Base === v
|
189
189
|
}
|
190
190
|
|
191
191
|
# We can't cache Post.find_by(author: david) ...yet
|
data/lib/active_record/enum.rb
CHANGED
@@ -535,17 +535,17 @@ module ActiveRecord
|
|
535
535
|
|
536
536
|
update_all_loaded_fixtures fixtures_map
|
537
537
|
|
538
|
-
connection.transaction(:
|
539
|
-
deleted_tables = Set.new
|
538
|
+
connection.transaction(requires_new: true) do
|
539
|
+
deleted_tables = Hash.new { |h, k| h[k] = Set.new }
|
540
540
|
fixture_sets.each do |fs|
|
541
541
|
conn = fs.model_class.respond_to?(:connection) ? fs.model_class.connection : connection
|
542
542
|
table_rows = fs.table_rows
|
543
543
|
|
544
544
|
table_rows.each_key do |table|
|
545
|
-
unless deleted_tables.include? table
|
546
|
-
conn.delete "DELETE FROM #{conn.quote_table_name(table)}",
|
545
|
+
unless deleted_tables[conn].include? table
|
546
|
+
conn.delete "DELETE FROM #{conn.quote_table_name(table)}", "Fixture Delete"
|
547
547
|
end
|
548
|
-
deleted_tables << table
|
548
|
+
deleted_tables[conn] << table
|
549
549
|
end
|
550
550
|
|
551
551
|
table_rows.each do |fixture_set_name, rows|
|
@@ -1169,9 +1169,10 @@ module ActiveRecord
|
|
1169
1169
|
def run_without_lock
|
1170
1170
|
migration = migrations.detect { |m| m.version == @target_version }
|
1171
1171
|
raise UnknownMigrationVersionError.new(@target_version) if migration.nil?
|
1172
|
-
execute_migration_in_transaction(migration, @direction)
|
1172
|
+
result = execute_migration_in_transaction(migration, @direction)
|
1173
1173
|
|
1174
1174
|
record_environment
|
1175
|
+
result
|
1175
1176
|
end
|
1176
1177
|
|
1177
1178
|
# Used for running multiple migrations up to or down to a certain value.
|
@@ -1180,11 +1181,12 @@ module ActiveRecord
|
|
1180
1181
|
raise UnknownMigrationVersionError.new(@target_version)
|
1181
1182
|
end
|
1182
1183
|
|
1183
|
-
runnable.each do |migration|
|
1184
|
+
result = runnable.each do |migration|
|
1184
1185
|
execute_migration_in_transaction(migration, @direction)
|
1185
1186
|
end
|
1186
1187
|
|
1187
1188
|
record_environment
|
1189
|
+
result
|
1188
1190
|
end
|
1189
1191
|
|
1190
1192
|
# Stores the current environment in the database.
|
@@ -330,10 +330,10 @@ module ActiveRecord
|
|
330
330
|
self
|
331
331
|
end
|
332
332
|
|
333
|
-
# Wrapper around #increment that
|
334
|
-
#
|
335
|
-
#
|
336
|
-
#
|
333
|
+
# Wrapper around #increment that writes the update to the database.
|
334
|
+
# Only +attribute+ is updated; the record itself is not saved.
|
335
|
+
# This means that any other modified attributes will still be dirty.
|
336
|
+
# Validations and callbacks are skipped. Returns +self+.
|
337
337
|
def increment!(attribute, by = 1)
|
338
338
|
increment(attribute, by)
|
339
339
|
change = public_send(attribute) - (attribute_was(attribute.to_s) || 0)
|
@@ -349,10 +349,10 @@ module ActiveRecord
|
|
349
349
|
increment(attribute, -by)
|
350
350
|
end
|
351
351
|
|
352
|
-
# Wrapper around #decrement that
|
353
|
-
#
|
354
|
-
#
|
355
|
-
#
|
352
|
+
# Wrapper around #decrement that writes the update to the database.
|
353
|
+
# Only +attribute+ is updated; the record itself is not saved.
|
354
|
+
# This means that any other modified attributes will still be dirty.
|
355
|
+
# Validations and callbacks are skipped. Returns +self+.
|
356
356
|
def decrement!(attribute, by = 1)
|
357
357
|
increment!(attribute, -by)
|
358
358
|
end
|
@@ -399,7 +399,7 @@ module ActiveRecord
|
|
399
399
|
end
|
400
400
|
|
401
401
|
def association_primary_key_type
|
402
|
-
klass.type_for_attribute(association_primary_key)
|
402
|
+
klass.type_for_attribute(association_primary_key.to_s)
|
403
403
|
end
|
404
404
|
|
405
405
|
def active_record_primary_key
|
@@ -856,7 +856,7 @@ module ActiveRecord
|
|
856
856
|
end
|
857
857
|
|
858
858
|
def association_primary_key_type
|
859
|
-
klass.type_for_attribute(association_primary_key)
|
859
|
+
klass.type_for_attribute(association_primary_key.to_s)
|
860
860
|
end
|
861
861
|
|
862
862
|
# Gets an array of possible <tt>:through</tt> source reflection names in both singular and plural form.
|
@@ -37,6 +37,7 @@ module ActiveRecord
|
|
37
37
|
|
38
38
|
delegate :to_xml, :encode_with, :length, :collect, :map, :each, :all?, :include?, :to_ary, :join,
|
39
39
|
:[], :&, :|, :+, :-, :sample, :reverse, :compact, :in_groups, :in_groups_of,
|
40
|
+
:to_sentence, :to_formatted_s,
|
40
41
|
:shuffle, :split, :index, to: :records
|
41
42
|
|
42
43
|
delegate :table_name, :quoted_table_name, :primary_key, :quoted_primary_key,
|
@@ -17,8 +17,8 @@ module ActiveRecord
|
|
17
17
|
# Person.where("administrator = 1").order("created_on DESC").find(1)
|
18
18
|
#
|
19
19
|
# NOTE: The returned records may not be in the same order as the ids you
|
20
|
-
# provide since database rows are unordered. You
|
21
|
-
# option if you want the results
|
20
|
+
# provide since database rows are unordered. You will need to provide an explicit QueryMethods#order
|
21
|
+
# option if you want the results to be sorted.
|
22
22
|
#
|
23
23
|
# ==== Find with lock
|
24
24
|
#
|
@@ -9,7 +9,7 @@ module ActiveRecord #:nodoc:
|
|
9
9
|
end
|
10
10
|
|
11
11
|
def serializable_hash(options = nil)
|
12
|
-
options = options.try(:
|
12
|
+
options = options.try(:dup) || {}
|
13
13
|
|
14
14
|
options[:except] = Array(options[:except]).map(&:to_s)
|
15
15
|
options[:except] |= Array(self.class.inheritance_column)
|
@@ -10,7 +10,7 @@ module ActiveRecord
|
|
10
10
|
def create_migration_file
|
11
11
|
set_local_assigns!
|
12
12
|
validate_file_name!
|
13
|
-
migration_template @migration_template, "
|
13
|
+
migration_template @migration_template, File.join(db_migrate_path, "#{file_name}.rb")
|
14
14
|
end
|
15
15
|
|
16
16
|
protected
|
@@ -68,6 +68,14 @@ module ActiveRecord
|
|
68
68
|
def normalize_table_name(_table_name)
|
69
69
|
pluralize_table_names? ? _table_name.pluralize : _table_name.singularize
|
70
70
|
end
|
71
|
+
|
72
|
+
def db_migrate_path
|
73
|
+
if defined?(Rails) && Rails.application
|
74
|
+
Rails.application.config.paths["db/migrate"].to_ary.first
|
75
|
+
else
|
76
|
+
"db/migrate"
|
77
|
+
end
|
78
|
+
end
|
71
79
|
end
|
72
80
|
end
|
73
81
|
end
|
@@ -17,7 +17,7 @@ module ActiveRecord
|
|
17
17
|
def create_migration_file
|
18
18
|
return unless options[:migration] && options[:parent].nil?
|
19
19
|
attributes.each { |a| a.attr_options.delete(:index) if a.reference? && !a.has_index? } if options[:indexes] == false
|
20
|
-
migration_template "../../migration/templates/create_table_migration.rb", "
|
20
|
+
migration_template "../../migration/templates/create_table_migration.rb", File.join(db_migrate_path, "create_#{table_name}.rb")
|
21
21
|
end
|
22
22
|
|
23
23
|
def create_model_file
|
@@ -64,6 +64,14 @@ module ActiveRecord
|
|
64
64
|
'app/models/application_record.rb'
|
65
65
|
end
|
66
66
|
end
|
67
|
+
|
68
|
+
def db_migrate_path
|
69
|
+
if defined?(Rails) && Rails.application
|
70
|
+
Rails.application.config.paths["db/migrate"].to_ary.first
|
71
|
+
else
|
72
|
+
"db/migrate"
|
73
|
+
end
|
74
|
+
end
|
67
75
|
end
|
68
76
|
end
|
69
77
|
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.0.
|
4
|
+
version: 5.0.2.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: 2017-02-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -16,28 +16,28 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - '='
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 5.0.
|
19
|
+
version: 5.0.2.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.0.
|
26
|
+
version: 5.0.2.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.0.
|
33
|
+
version: 5.0.2.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.0.
|
40
|
+
version: 5.0.2.rc1
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: arel
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -323,14 +323,13 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
323
323
|
version: 2.2.2
|
324
324
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
325
325
|
requirements:
|
326
|
-
- - "
|
326
|
+
- - ">"
|
327
327
|
- !ruby/object:Gem::Version
|
328
|
-
version:
|
328
|
+
version: 1.3.1
|
329
329
|
requirements: []
|
330
330
|
rubyforge_project:
|
331
|
-
rubygems_version: 2.
|
331
|
+
rubygems_version: 2.6.10
|
332
332
|
signing_key:
|
333
333
|
specification_version: 4
|
334
334
|
summary: Object-relational mapper framework (part of Rails).
|
335
335
|
test_files: []
|
336
|
-
has_rdoc:
|