activerecord 4.2.0.beta3 → 4.2.0.beta4
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 +35 -2
- data/lib/active_record/associations.rb +6 -0
- data/lib/active_record/associations/builder/has_and_belongs_to_many.rb +1 -1
- data/lib/active_record/associations/collection_association.rb +6 -1
- data/lib/active_record/associations/collection_proxy.rb +14 -17
- data/lib/active_record/associations/has_many_through_association.rb +9 -6
- data/lib/active_record/associations/join_dependency.rb +12 -3
- data/lib/active_record/associations/join_dependency/join_part.rb +0 -1
- data/lib/active_record/associations/singular_association.rb +6 -1
- data/lib/active_record/attribute_methods.rb +7 -4
- data/lib/active_record/attribute_methods/serialization.rb +8 -7
- data/lib/active_record/attribute_set/builder.rb +5 -2
- data/lib/active_record/autosave_association.rb +3 -1
- data/lib/active_record/callbacks.rb +5 -5
- data/lib/active_record/connection_adapters/abstract/connection_pool.rb +8 -6
- data/lib/active_record/connection_adapters/abstract/database_statements.rb +2 -1
- data/lib/active_record/connection_adapters/abstract/quoting.rb +1 -1
- data/lib/active_record/connection_adapters/abstract/schema_definitions.rb +11 -18
- data/lib/active_record/connection_adapters/abstract/schema_dumper.rb +1 -1
- data/lib/active_record/connection_adapters/abstract/schema_statements.rb +1 -1
- data/lib/active_record/connection_adapters/abstract_mysql_adapter.rb +20 -9
- data/lib/active_record/connection_adapters/column.rb +20 -0
- data/lib/active_record/connection_adapters/connection_specification.rb +8 -3
- data/lib/active_record/connection_adapters/mysql2_adapter.rb +0 -5
- data/lib/active_record/connection_adapters/mysql_adapter.rb +1 -1
- data/lib/active_record/connection_adapters/postgresql/oid/cidr.rb +3 -3
- data/lib/active_record/connection_adapters/postgresql/oid/range.rb +7 -4
- data/lib/active_record/connection_adapters/postgresql/oid/type_map_initializer.rb +1 -1
- data/lib/active_record/connection_adapters/postgresql/quoting.rb +1 -1
- data/lib/active_record/connection_adapters/postgresql_adapter.rb +4 -8
- data/lib/active_record/connection_adapters/sqlite3_adapter.rb +0 -4
- data/lib/active_record/core.rb +14 -9
- data/lib/active_record/errors.rb +1 -1
- data/lib/active_record/fixtures.rb +3 -35
- data/lib/active_record/gem_version.rb +1 -1
- data/lib/active_record/inheritance.rb +2 -2
- data/lib/active_record/model_schema.rb +8 -11
- data/lib/active_record/querying.rb +12 -2
- data/lib/active_record/railties/databases.rake +1 -1
- data/lib/active_record/reflection.rb +24 -12
- data/lib/active_record/relation.rb +2 -3
- data/lib/active_record/relation/finder_methods.rb +19 -10
- data/lib/active_record/relation/merger.rb +15 -15
- data/lib/active_record/relation/predicate_builder.rb +1 -1
- data/lib/active_record/relation/predicate_builder/array_handler.rb +9 -4
- data/lib/active_record/relation/query_methods.rb +6 -3
- data/lib/active_record/result.rb +4 -0
- data/lib/active_record/schema_dumper.rb +2 -0
- data/lib/active_record/scoping/named.rb +4 -0
- data/lib/active_record/tasks/database_tasks.rb +6 -3
- data/lib/active_record/transactions.rb +3 -3
- data/lib/active_record/type/boolean.rb +12 -1
- data/lib/active_record/validations/associated.rb +5 -3
- data/lib/active_record/validations/presence.rb +5 -3
- metadata +16 -16
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ce2a22714e7ecce16ad964d1f2f3725feb2b1920
|
4
|
+
data.tar.gz: 8812b21dadc7a62d5ff64a05ebec8fa8edc31558
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 907e24f6a9edc6d5ce51166fc225c3cd033cf00d0405e4e247aa0bf2721e9c4032a1708a7bc887d4109acdb3cd96dce5b37698985b9993d25d9d405785323f3c
|
7
|
+
data.tar.gz: 547b9bb76efcdb0cb6b56ab8ae31f17ee528a053ee593b2e041406a11edbba209a1cef87ff539863544e840a542f5474274d2448b6bbeb448b9e4f7ffcf38721
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,38 @@
|
|
1
|
+
* MySQL enum type lookups, with values matching another type, no longer result
|
2
|
+
in an endless loop.
|
3
|
+
|
4
|
+
Fixes #17402.
|
5
|
+
|
6
|
+
*Yves Senn*
|
7
|
+
|
8
|
+
* Raise `ArgumentError` when the body of a scope is not callable.
|
9
|
+
|
10
|
+
*Mauro George*
|
11
|
+
|
12
|
+
* Use type column first in multi-column indexes created with `add-reference`.
|
13
|
+
|
14
|
+
*Derek Prior*
|
15
|
+
|
16
|
+
* Fix `Relation.rewhere` to work with Range values.
|
17
|
+
|
18
|
+
*Dan Olson*
|
19
|
+
|
20
|
+
* `AR::UnknownAttributeError` now includes the class name of a record.
|
21
|
+
|
22
|
+
User.new(name: "Yuki Nishijima", project_attributes: {name: "kaminari"})
|
23
|
+
# => ActiveRecord::UnknownAttributeError: unknown attribute 'name' for User.
|
24
|
+
|
25
|
+
*Yuki Nishijima*
|
26
|
+
|
27
|
+
* Fix regression causing `after_create` callbacks to run before associated
|
28
|
+
records are autosaved.
|
29
|
+
|
30
|
+
Fixes #17209.
|
31
|
+
|
32
|
+
*Agis Anastasopoulos*
|
33
|
+
|
1
34
|
* Honor overridden `rack.test` in Rack environment for the connection
|
2
|
-
management
|
35
|
+
management middleware.
|
3
36
|
|
4
37
|
*Simon Eskildsen*
|
5
38
|
|
@@ -213,7 +246,7 @@
|
|
213
246
|
|
214
247
|
*Kenn Ejima*
|
215
248
|
|
216
|
-
* Add support for
|
249
|
+
* Add support for PostgreSQL JSONB.
|
217
250
|
|
218
251
|
Example:
|
219
252
|
|
@@ -46,6 +46,12 @@ module ActiveRecord
|
|
46
46
|
end
|
47
47
|
end
|
48
48
|
|
49
|
+
class HasOneAssociationPolymorphicThroughError < ActiveRecordError #:nodoc:
|
50
|
+
def initialize(owner_class_name, reflection)
|
51
|
+
super("Cannot have a has_one :through association '#{owner_class_name}##{reflection.name}' which goes through the polymorphic association '#{owner_class_name}##{reflection.through_reflection.name}'.")
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
49
55
|
class HasManyThroughSourceAssociationNotFoundError < ActiveRecordError #:nodoc:
|
50
56
|
def initialize(reflection)
|
51
57
|
through_reflection = reflection.through_reflection
|
@@ -11,7 +11,7 @@ module ActiveRecord::Associations::Builder
|
|
11
11
|
end
|
12
12
|
|
13
13
|
def join_table
|
14
|
-
@join_table ||= [@lhs_class.table_name, klass.table_name].sort.join("\0").gsub(/^(.*[._])(.+)\0\1(.+)/, '\1\2_\3').
|
14
|
+
@join_table ||= [@lhs_class.table_name, klass.table_name].sort.join("\0").gsub(/^(.*[._])(.+)\0\1(.+)/, '\1\2_\3').tr("\0", "_")
|
15
15
|
end
|
16
16
|
|
17
17
|
private
|
@@ -407,7 +407,12 @@ module ActiveRecord
|
|
407
407
|
|
408
408
|
private
|
409
409
|
def get_records
|
410
|
-
|
410
|
+
if reflection.scope_chain.any?(&:any?) ||
|
411
|
+
scope.eager_loading? ||
|
412
|
+
klass.current_scope
|
413
|
+
|
414
|
+
return scope.to_a
|
415
|
+
end
|
411
416
|
|
412
417
|
conn = klass.connection
|
413
418
|
sc = reflection.association_scope_cache(conn, owner) do
|
@@ -355,14 +355,15 @@ module ActiveRecord
|
|
355
355
|
@association.replace(other_array)
|
356
356
|
end
|
357
357
|
|
358
|
-
# Deletes all the records from the collection
|
359
|
-
#
|
360
|
-
#
|
358
|
+
# Deletes all the records from the collection according to the strategy
|
359
|
+
# specified by the +:dependent+ option. If no +:dependent+ option is given,
|
360
|
+
# then it will follow the default strategy.
|
361
361
|
#
|
362
|
-
#
|
363
|
-
#
|
364
|
-
#
|
365
|
-
# the default strategy is
|
362
|
+
# For +has_many :through+ associations, the default deletion strategy is
|
363
|
+
# +:delete_all+.
|
364
|
+
#
|
365
|
+
# For +has_many+ associations, the default deletion strategy is +:nullify+.
|
366
|
+
# This sets the foreign keys to +NULL+.
|
366
367
|
#
|
367
368
|
# class Person < ActiveRecord::Base
|
368
369
|
# has_many :pets # dependent: :nullify option by default
|
@@ -393,9 +394,9 @@ module ActiveRecord
|
|
393
394
|
# # #<Pet id: 3, name: "Choo-Choo", person_id: nil>
|
394
395
|
# # ]
|
395
396
|
#
|
396
|
-
#
|
397
|
-
#
|
398
|
-
#
|
397
|
+
# Both +has_many+ and +has_many :through+ dependencies default to the
|
398
|
+
# +:delete_all+ strategy if the +:dependent+ option is set to +:destroy+.
|
399
|
+
# Records are not instantiated and callbacks will not be fired.
|
399
400
|
#
|
400
401
|
# class Person < ActiveRecord::Base
|
401
402
|
# has_many :pets, dependent: :destroy
|
@@ -410,11 +411,6 @@ module ActiveRecord
|
|
410
411
|
# # ]
|
411
412
|
#
|
412
413
|
# person.pets.delete_all
|
413
|
-
# # => [
|
414
|
-
# # #<Pet id: 1, name: "Fancy-Fancy", person_id: 1>,
|
415
|
-
# # #<Pet id: 2, name: "Spook", person_id: 1>,
|
416
|
-
# # #<Pet id: 3, name: "Choo-Choo", person_id: 1>
|
417
|
-
# # ]
|
418
414
|
#
|
419
415
|
# Pet.find(1, 2, 3)
|
420
416
|
# # => ActiveRecord::RecordNotFound
|
@@ -443,8 +439,9 @@ module ActiveRecord
|
|
443
439
|
end
|
444
440
|
|
445
441
|
# Deletes the records of the collection directly from the database
|
446
|
-
# ignoring the +:dependent+ option.
|
447
|
-
# +after_remove+ , +before_destroy+ and
|
442
|
+
# ignoring the +:dependent+ option. Records are instantiated and it
|
443
|
+
# invokes +before_remove+, +after_remove+ , +before_destroy+ and
|
444
|
+
# +after_destroy+ callbacks.
|
448
445
|
#
|
449
446
|
# class Person < ActiveRecord::Base
|
450
447
|
# has_many :pets
|
@@ -1,3 +1,5 @@
|
|
1
|
+
require 'active_support/core_ext/string/filters'
|
2
|
+
|
1
3
|
module ActiveRecord
|
2
4
|
# = Active Record Has Many Through Association
|
3
5
|
module Associations
|
@@ -63,11 +65,12 @@ module ActiveRecord
|
|
63
65
|
|
64
66
|
save_through_record(record)
|
65
67
|
if has_cached_counter? && !through_reflection_updates_counter_cache?
|
66
|
-
ActiveSupport::Deprecation.warn
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
68
|
+
ActiveSupport::Deprecation.warn(<<-MSG.squish)
|
69
|
+
Automatic updating of counter caches on through associations has been
|
70
|
+
deprecated, and will be removed in Rails 5. Instead, please set the
|
71
|
+
appropriate `counter_cache` options on the `has_many` and `belongs_to`
|
72
|
+
for your associations to #{through_reflection.name}.
|
73
|
+
MSG
|
71
74
|
|
72
75
|
update_counter_in_database(1)
|
73
76
|
end
|
@@ -159,7 +162,7 @@ module ActiveRecord
|
|
159
162
|
count = scope.destroy_all.length
|
160
163
|
else
|
161
164
|
scope.to_a.each do |record|
|
162
|
-
record.
|
165
|
+
record._run_destroy_callbacks
|
163
166
|
end
|
164
167
|
|
165
168
|
arel = scope.arel
|
@@ -142,11 +142,20 @@ module ActiveRecord
|
|
142
142
|
parents = model_cache[join_root]
|
143
143
|
column_aliases = aliases.column_aliases join_root
|
144
144
|
|
145
|
-
|
146
|
-
|
147
|
-
|
145
|
+
message_bus = ActiveSupport::Notifications.instrumenter
|
146
|
+
|
147
|
+
payload = {
|
148
|
+
record_count: result_set.length,
|
149
|
+
class_name: join_root.base_klass.name
|
148
150
|
}
|
149
151
|
|
152
|
+
message_bus.instrument('instantiation.active_record', payload) do
|
153
|
+
result_set.each { |row_hash|
|
154
|
+
parent = parents[row_hash[primary_key]] ||= join_root.instantiate(row_hash, column_aliases)
|
155
|
+
construct(parent, join_root, row_hash, result_set, seen, model_cache, aliases)
|
156
|
+
}
|
157
|
+
end
|
158
|
+
|
150
159
|
parents.values
|
151
160
|
end
|
152
161
|
|
@@ -39,7 +39,12 @@ module ActiveRecord
|
|
39
39
|
end
|
40
40
|
|
41
41
|
def get_records
|
42
|
-
|
42
|
+
if reflection.scope_chain.any?(&:any?) ||
|
43
|
+
scope.eager_loading? ||
|
44
|
+
klass.current_scope
|
45
|
+
|
46
|
+
return scope.limit(1).to_a
|
47
|
+
end
|
43
48
|
|
44
49
|
conn = klass.connection
|
45
50
|
sc = reflection.association_scope_cache(conn, owner) do
|
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'active_support/core_ext/enumerable'
|
2
|
+
require 'active_support/core_ext/string/filters'
|
2
3
|
require 'mutex_m'
|
3
4
|
require 'thread_safe'
|
4
5
|
|
@@ -90,7 +91,7 @@ module ActiveRecord
|
|
90
91
|
|
91
92
|
def undefine_attribute_methods # :nodoc:
|
92
93
|
generated_attribute_methods.synchronize do
|
93
|
-
super if @attribute_methods_generated
|
94
|
+
super if defined?(@attribute_methods_generated) && @attribute_methods_generated
|
94
95
|
@attribute_methods_generated = false
|
95
96
|
end
|
96
97
|
end
|
@@ -205,9 +206,11 @@ module ActiveRecord
|
|
205
206
|
def column_for_attribute(name)
|
206
207
|
column = columns_hash[name.to_s]
|
207
208
|
if column.nil?
|
208
|
-
ActiveSupport::Deprecation.warn
|
209
|
-
|
210
|
-
|
209
|
+
ActiveSupport::Deprecation.warn(<<-MSG.squish)
|
210
|
+
`#column_for_attribute` will return a null object for non-existent
|
211
|
+
columns in Rails 5. Use `#has_attribute?` if you need to check for
|
212
|
+
an attribute's existence.
|
213
|
+
MSG
|
211
214
|
end
|
212
215
|
column
|
213
216
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
require 'active_support/core_ext/string/filters'
|
2
|
+
|
1
3
|
module ActiveRecord
|
2
4
|
module AttributeMethods
|
3
5
|
module Serialization
|
@@ -8,11 +10,8 @@ module ActiveRecord
|
|
8
10
|
# object, and retrieved as the same object, then specify the name of that
|
9
11
|
# attribute using this method and it will be handled automatically. The
|
10
12
|
# serialization is done through YAML. If +class_name+ is specified, the
|
11
|
-
# serialized object must be of that class on retrieval
|
12
|
-
# <tt>SerializationTypeMismatch</tt> will be raised.
|
13
|
-
#
|
14
|
-
# A notable side effect of serialized attributes is that the model will
|
15
|
-
# be updated on every save, even if it is not dirty.
|
13
|
+
# serialized object must be of that class on assignment and retrieval.
|
14
|
+
# Otherwise <tt>SerializationTypeMismatch</tt> will be raised.
|
16
15
|
#
|
17
16
|
# ==== Parameters
|
18
17
|
#
|
@@ -54,8 +53,10 @@ module ActiveRecord
|
|
54
53
|
end
|
55
54
|
|
56
55
|
def serialized_attributes
|
57
|
-
ActiveSupport::Deprecation.warn
|
58
|
-
|
56
|
+
ActiveSupport::Deprecation.warn(<<-MSG.squish)
|
57
|
+
`serialized_attributes` is deprecated without replacement, and will
|
58
|
+
be removed in Rails 5.0.
|
59
|
+
MSG
|
59
60
|
|
60
61
|
@serialized_attributes ||= Hash[
|
61
62
|
columns.select { |t| t.cast_type.is_a?(Type::Serialized) }.map { |c|
|
@@ -23,8 +23,11 @@ module ActiveRecord
|
|
23
23
|
end
|
24
24
|
|
25
25
|
def add_uninitialized_attributes(attributes)
|
26
|
-
types.
|
27
|
-
|
26
|
+
types.each_key do |name|
|
27
|
+
next if attributes.key? name
|
28
|
+
type = types[name]
|
29
|
+
attributes[name] =
|
30
|
+
Attribute.uninitialized(name, type)
|
28
31
|
end
|
29
32
|
end
|
30
33
|
end
|
@@ -184,7 +184,9 @@ module ActiveRecord
|
|
184
184
|
before_save :before_save_collection_association
|
185
185
|
|
186
186
|
define_non_cyclic_method(save_method) { save_collection_association(reflection) }
|
187
|
-
after_save
|
187
|
+
# Doesn't use after_save as that would save associations added in after_create/after_update twice
|
188
|
+
after_create save_method
|
189
|
+
after_update save_method
|
188
190
|
elsif reflection.has_one?
|
189
191
|
define_method(save_method) { save_has_one_association(reflection) } unless method_defined?(save_method)
|
190
192
|
# Configures two callbacks instead of a single after_save so that
|
@@ -289,25 +289,25 @@ module ActiveRecord
|
|
289
289
|
end
|
290
290
|
|
291
291
|
def destroy #:nodoc:
|
292
|
-
|
292
|
+
_run_destroy_callbacks { super }
|
293
293
|
end
|
294
294
|
|
295
295
|
def touch(*) #:nodoc:
|
296
|
-
|
296
|
+
_run_touch_callbacks { super }
|
297
297
|
end
|
298
298
|
|
299
299
|
private
|
300
300
|
|
301
301
|
def create_or_update #:nodoc:
|
302
|
-
|
302
|
+
_run_save_callbacks { super }
|
303
303
|
end
|
304
304
|
|
305
305
|
def _create_record #:nodoc:
|
306
|
-
|
306
|
+
_run_create_callbacks { super }
|
307
307
|
end
|
308
308
|
|
309
309
|
def _update_record(*) #:nodoc:
|
310
|
-
|
310
|
+
_run_update_callbacks { super }
|
311
311
|
end
|
312
312
|
end
|
313
313
|
end
|
@@ -2,6 +2,7 @@ require 'thread'
|
|
2
2
|
require 'thread_safe'
|
3
3
|
require 'monitor'
|
4
4
|
require 'set'
|
5
|
+
require 'active_support/core_ext/string/filters'
|
5
6
|
|
6
7
|
module ActiveRecord
|
7
8
|
# Raised when a connection could not be obtained within the connection
|
@@ -360,7 +361,7 @@ module ActiveRecord
|
|
360
361
|
synchronize do
|
361
362
|
owner = conn.owner
|
362
363
|
|
363
|
-
conn.
|
364
|
+
conn._run_checkin_callbacks do
|
364
365
|
conn.expire
|
365
366
|
end
|
366
367
|
|
@@ -449,7 +450,7 @@ module ActiveRecord
|
|
449
450
|
end
|
450
451
|
|
451
452
|
def checkout_and_verify(c)
|
452
|
-
c.
|
453
|
+
c._run_checkout_callbacks do
|
453
454
|
c.verify!
|
454
455
|
end
|
455
456
|
c
|
@@ -518,10 +519,11 @@ module ActiveRecord
|
|
518
519
|
end
|
519
520
|
|
520
521
|
def connection_pools
|
521
|
-
ActiveSupport::Deprecation.warn(
|
522
|
-
|
523
|
-
|
524
|
-
|
522
|
+
ActiveSupport::Deprecation.warn(<<-MSG.squish)
|
523
|
+
In the next release, this will return the same as `#connection_pool_list`.
|
524
|
+
(An array of pools, rather than a hash mapping specs to pools.)
|
525
|
+
MSG
|
526
|
+
|
525
527
|
Hash[connection_pool_list.map { |pool| [pool.spec, pool] }]
|
526
528
|
end
|
527
529
|
|
@@ -337,8 +337,9 @@ module ActiveRecord
|
|
337
337
|
|
338
338
|
# Returns an ActiveRecord::Result instance.
|
339
339
|
def select(sql, name = nil, binds = [])
|
340
|
+
exec_query(sql, name, binds)
|
340
341
|
end
|
341
|
-
|
342
|
+
|
342
343
|
|
343
344
|
# Returns the last auto-generated ID from the affected table.
|
344
345
|
def insert_sql(sql, name = nil, pk = nil, id_value = nil, sequence_name = nil)
|
@@ -108,7 +108,7 @@ module ActiveRecord
|
|
108
108
|
when Numeric, ActiveSupport::Duration then value.to_s
|
109
109
|
when Date, Time then "'#{quoted_date(value)}'"
|
110
110
|
when Symbol then "'#{quote_string(value.to_s)}'"
|
111
|
-
when Class then "'#{value
|
111
|
+
when Class then "'#{value}'"
|
112
112
|
else
|
113
113
|
"'#{quote_string(YAML.dump(value))}'"
|
114
114
|
end
|
@@ -60,11 +60,11 @@ module ActiveRecord
|
|
60
60
|
def emit_warning_if_null_unspecified(options)
|
61
61
|
return if options.key?(:null)
|
62
62
|
|
63
|
-
ActiveSupport::Deprecation.warn
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
63
|
+
ActiveSupport::Deprecation.warn(<<-MSG.squish)
|
64
|
+
`#timestamp` was called without specifying an option for `null`. In Rails 5,
|
65
|
+
this behavior will change to `null: false`. You should manually specify
|
66
|
+
`null: true` to prevent the behavior of your existing migrations from changing.
|
67
|
+
MSG
|
68
68
|
end
|
69
69
|
end
|
70
70
|
|
@@ -256,7 +256,7 @@ module ActiveRecord
|
|
256
256
|
name = name.to_s
|
257
257
|
type = type.to_sym
|
258
258
|
|
259
|
-
if
|
259
|
+
if @columns_hash[name] && @columns_hash[name].primary_key?
|
260
260
|
raise ArgumentError, "you can't redefine the primary key column '#{name}'. To define a custom primary key, pass { id: false } to create_table."
|
261
261
|
end
|
262
262
|
|
@@ -270,7 +270,7 @@ module ActiveRecord
|
|
270
270
|
@columns_hash.delete name.to_s
|
271
271
|
end
|
272
272
|
|
273
|
-
[:string, :text, :integer, :float, :decimal, :datetime, :timestamp, :time, :date, :binary, :boolean].each do |column_type|
|
273
|
+
[:string, :text, :integer, :bigint, :float, :decimal, :datetime, :timestamp, :time, :date, :binary, :boolean].each do |column_type|
|
274
274
|
define_method column_type do |*args|
|
275
275
|
options = args.extract_options!
|
276
276
|
column_names = args
|
@@ -312,13 +312,13 @@ module ActiveRecord
|
|
312
312
|
args.each do |col|
|
313
313
|
column("#{col}_id", type, options)
|
314
314
|
column("#{col}_type", :string, polymorphic.is_a?(Hash) ? polymorphic : options) if polymorphic
|
315
|
-
index(polymorphic ? %w(id
|
315
|
+
index(polymorphic ? %w(type id).map { |t| "#{col}_#{t}" } : "#{col}_id", index_options.is_a?(Hash) ? index_options : {}) if index_options
|
316
316
|
end
|
317
317
|
end
|
318
318
|
alias :belongs_to :references
|
319
319
|
|
320
320
|
def new_column_definition(name, type, options) # :nodoc:
|
321
|
-
type = aliased_types
|
321
|
+
type = aliased_types(type.to_s, type)
|
322
322
|
column = create_column_definition name, type
|
323
323
|
limit = options.fetch(:limit) do
|
324
324
|
native[type][:limit] if native[type].is_a?(Hash)
|
@@ -340,19 +340,12 @@ module ActiveRecord
|
|
340
340
|
ColumnDefinition.new name, type
|
341
341
|
end
|
342
342
|
|
343
|
-
def primary_key_column_name
|
344
|
-
primary_key_column = columns.detect { |c| c.primary_key? }
|
345
|
-
primary_key_column && primary_key_column.name
|
346
|
-
end
|
347
|
-
|
348
343
|
def native
|
349
344
|
@native
|
350
345
|
end
|
351
346
|
|
352
|
-
def aliased_types
|
353
|
-
|
354
|
-
timestamp: :datetime,
|
355
|
-
)
|
347
|
+
def aliased_types(name, fallback)
|
348
|
+
'timestamp' == name ? :datetime : fallback
|
356
349
|
end
|
357
350
|
end
|
358
351
|
|