activerecord 3.2.22.5 → 4.2.11.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 +1632 -609
- data/MIT-LICENSE +1 -1
- data/README.rdoc +37 -41
- data/examples/performance.rb +31 -19
- data/examples/simple.rb +4 -4
- data/lib/active_record/aggregations.rb +56 -42
- data/lib/active_record/association_relation.rb +35 -0
- data/lib/active_record/associations/alias_tracker.rb +47 -36
- data/lib/active_record/associations/association.rb +73 -55
- data/lib/active_record/associations/association_scope.rb +143 -82
- data/lib/active_record/associations/belongs_to_association.rb +65 -25
- data/lib/active_record/associations/belongs_to_polymorphic_association.rb +7 -2
- data/lib/active_record/associations/builder/association.rb +125 -31
- data/lib/active_record/associations/builder/belongs_to.rb +89 -61
- data/lib/active_record/associations/builder/collection_association.rb +69 -49
- data/lib/active_record/associations/builder/has_and_belongs_to_many.rb +113 -42
- data/lib/active_record/associations/builder/has_many.rb +8 -64
- data/lib/active_record/associations/builder/has_one.rb +12 -51
- data/lib/active_record/associations/builder/singular_association.rb +23 -17
- data/lib/active_record/associations/collection_association.rb +251 -177
- data/lib/active_record/associations/collection_proxy.rb +963 -63
- data/lib/active_record/associations/foreign_association.rb +11 -0
- data/lib/active_record/associations/has_many_association.rb +113 -22
- data/lib/active_record/associations/has_many_through_association.rb +99 -39
- data/lib/active_record/associations/has_one_association.rb +43 -20
- data/lib/active_record/associations/has_one_through_association.rb +1 -1
- data/lib/active_record/associations/join_dependency/join_association.rb +76 -107
- data/lib/active_record/associations/join_dependency/join_base.rb +7 -9
- data/lib/active_record/associations/join_dependency/join_part.rb +30 -37
- data/lib/active_record/associations/join_dependency.rb +230 -156
- data/lib/active_record/associations/preloader/association.rb +96 -55
- data/lib/active_record/associations/preloader/collection_association.rb +3 -3
- data/lib/active_record/associations/preloader/has_many_through.rb +7 -3
- data/lib/active_record/associations/preloader/has_one.rb +1 -1
- data/lib/active_record/associations/preloader/singular_association.rb +3 -3
- data/lib/active_record/associations/preloader/through_association.rb +62 -33
- data/lib/active_record/associations/preloader.rb +101 -79
- data/lib/active_record/associations/singular_association.rb +29 -13
- data/lib/active_record/associations/through_association.rb +30 -16
- data/lib/active_record/associations.rb +463 -345
- data/lib/active_record/attribute.rb +163 -0
- data/lib/active_record/attribute_assignment.rb +142 -151
- data/lib/active_record/attribute_decorators.rb +66 -0
- data/lib/active_record/attribute_methods/before_type_cast.rb +52 -7
- data/lib/active_record/attribute_methods/dirty.rb +137 -57
- data/lib/active_record/attribute_methods/primary_key.rb +50 -36
- data/lib/active_record/attribute_methods/query.rb +5 -4
- data/lib/active_record/attribute_methods/read.rb +73 -106
- data/lib/active_record/attribute_methods/serialization.rb +44 -94
- data/lib/active_record/attribute_methods/time_zone_conversion.rb +49 -45
- data/lib/active_record/attribute_methods/write.rb +57 -44
- data/lib/active_record/attribute_methods.rb +301 -141
- data/lib/active_record/attribute_set/builder.rb +106 -0
- data/lib/active_record/attribute_set.rb +81 -0
- data/lib/active_record/attributes.rb +147 -0
- data/lib/active_record/autosave_association.rb +246 -217
- data/lib/active_record/base.rb +70 -474
- data/lib/active_record/callbacks.rb +66 -28
- data/lib/active_record/coders/json.rb +13 -0
- data/lib/active_record/coders/yaml_column.rb +18 -21
- data/lib/active_record/connection_adapters/abstract/connection_pool.rb +396 -219
- data/lib/active_record/connection_adapters/abstract/database_limits.rb +9 -0
- data/lib/active_record/connection_adapters/abstract/database_statements.rb +167 -164
- data/lib/active_record/connection_adapters/abstract/query_cache.rb +29 -24
- data/lib/active_record/connection_adapters/abstract/quoting.rb +74 -55
- data/lib/active_record/connection_adapters/abstract/savepoints.rb +21 -0
- data/lib/active_record/connection_adapters/abstract/schema_creation.rb +125 -0
- data/lib/active_record/connection_adapters/abstract/schema_definitions.rb +261 -169
- data/lib/active_record/connection_adapters/abstract/schema_dumper.rb +50 -0
- data/lib/active_record/connection_adapters/abstract/schema_statements.rb +707 -259
- data/lib/active_record/connection_adapters/abstract/transaction.rb +215 -0
- data/lib/active_record/connection_adapters/abstract_adapter.rb +298 -89
- data/lib/active_record/connection_adapters/abstract_mysql_adapter.rb +466 -196
- data/lib/active_record/connection_adapters/column.rb +31 -245
- data/lib/active_record/connection_adapters/connection_specification.rb +275 -0
- data/lib/active_record/connection_adapters/mysql2_adapter.rb +45 -57
- data/lib/active_record/connection_adapters/mysql_adapter.rb +180 -123
- data/lib/active_record/connection_adapters/postgresql/array_parser.rb +93 -0
- data/lib/active_record/connection_adapters/postgresql/column.rb +20 -0
- data/lib/active_record/connection_adapters/postgresql/database_statements.rb +232 -0
- data/lib/active_record/connection_adapters/postgresql/oid/array.rb +100 -0
- data/lib/active_record/connection_adapters/postgresql/oid/bit.rb +52 -0
- data/lib/active_record/connection_adapters/postgresql/oid/bit_varying.rb +13 -0
- data/lib/active_record/connection_adapters/postgresql/oid/bytea.rb +15 -0
- data/lib/active_record/connection_adapters/postgresql/oid/cidr.rb +46 -0
- data/lib/active_record/connection_adapters/postgresql/oid/date.rb +11 -0
- data/lib/active_record/connection_adapters/postgresql/oid/date_time.rb +36 -0
- data/lib/active_record/connection_adapters/postgresql/oid/decimal.rb +13 -0
- data/lib/active_record/connection_adapters/postgresql/oid/enum.rb +19 -0
- data/lib/active_record/connection_adapters/postgresql/oid/float.rb +21 -0
- data/lib/active_record/connection_adapters/postgresql/oid/hstore.rb +59 -0
- data/lib/active_record/connection_adapters/postgresql/oid/inet.rb +13 -0
- data/lib/active_record/connection_adapters/postgresql/oid/infinity.rb +13 -0
- data/lib/active_record/connection_adapters/postgresql/oid/integer.rb +11 -0
- data/lib/active_record/connection_adapters/postgresql/oid/json.rb +35 -0
- data/lib/active_record/connection_adapters/postgresql/oid/jsonb.rb +23 -0
- data/lib/active_record/connection_adapters/postgresql/oid/money.rb +43 -0
- data/lib/active_record/connection_adapters/postgresql/oid/point.rb +43 -0
- data/lib/active_record/connection_adapters/postgresql/oid/range.rb +79 -0
- data/lib/active_record/connection_adapters/postgresql/oid/specialized_string.rb +19 -0
- data/lib/active_record/connection_adapters/postgresql/oid/time.rb +11 -0
- data/lib/active_record/connection_adapters/postgresql/oid/type_map_initializer.rb +109 -0
- data/lib/active_record/connection_adapters/postgresql/oid/uuid.rb +21 -0
- data/lib/active_record/connection_adapters/postgresql/oid/vector.rb +26 -0
- data/lib/active_record/connection_adapters/postgresql/oid/xml.rb +28 -0
- data/lib/active_record/connection_adapters/postgresql/oid.rb +36 -0
- data/lib/active_record/connection_adapters/postgresql/quoting.rb +108 -0
- data/lib/active_record/connection_adapters/postgresql/referential_integrity.rb +30 -0
- data/lib/active_record/connection_adapters/postgresql/schema_definitions.rb +152 -0
- data/lib/active_record/connection_adapters/postgresql/schema_statements.rb +596 -0
- data/lib/active_record/connection_adapters/postgresql/utils.rb +77 -0
- data/lib/active_record/connection_adapters/postgresql_adapter.rb +430 -999
- data/lib/active_record/connection_adapters/schema_cache.rb +52 -27
- data/lib/active_record/connection_adapters/sqlite3_adapter.rb +579 -22
- data/lib/active_record/connection_handling.rb +132 -0
- data/lib/active_record/core.rb +579 -0
- data/lib/active_record/counter_cache.rb +157 -105
- data/lib/active_record/dynamic_matchers.rb +119 -63
- data/lib/active_record/enum.rb +197 -0
- data/lib/active_record/errors.rb +94 -36
- data/lib/active_record/explain.rb +15 -63
- data/lib/active_record/explain_registry.rb +30 -0
- data/lib/active_record/explain_subscriber.rb +9 -5
- data/lib/active_record/fixture_set/file.rb +56 -0
- data/lib/active_record/fixtures.rb +302 -215
- data/lib/active_record/gem_version.rb +15 -0
- data/lib/active_record/inheritance.rb +143 -70
- data/lib/active_record/integration.rb +65 -12
- data/lib/active_record/legacy_yaml_adapter.rb +30 -0
- data/lib/active_record/locale/en.yml +8 -1
- data/lib/active_record/locking/optimistic.rb +73 -52
- data/lib/active_record/locking/pessimistic.rb +5 -5
- data/lib/active_record/log_subscriber.rb +24 -21
- data/lib/active_record/migration/command_recorder.rb +124 -32
- data/lib/active_record/migration/join_table.rb +15 -0
- data/lib/active_record/migration.rb +511 -213
- data/lib/active_record/model_schema.rb +91 -117
- data/lib/active_record/nested_attributes.rb +184 -130
- data/lib/active_record/no_touching.rb +52 -0
- data/lib/active_record/null_relation.rb +81 -0
- data/lib/active_record/persistence.rb +276 -117
- data/lib/active_record/query_cache.rb +19 -37
- data/lib/active_record/querying.rb +28 -18
- data/lib/active_record/railtie.rb +73 -40
- data/lib/active_record/railties/console_sandbox.rb +3 -4
- data/lib/active_record/railties/controller_runtime.rb +4 -3
- data/lib/active_record/railties/databases.rake +141 -416
- data/lib/active_record/railties/jdbcmysql_error.rb +1 -1
- data/lib/active_record/readonly_attributes.rb +1 -4
- data/lib/active_record/reflection.rb +513 -154
- data/lib/active_record/relation/batches.rb +91 -43
- data/lib/active_record/relation/calculations.rb +199 -161
- data/lib/active_record/relation/delegation.rb +116 -25
- data/lib/active_record/relation/finder_methods.rb +362 -248
- data/lib/active_record/relation/merger.rb +193 -0
- data/lib/active_record/relation/predicate_builder/array_handler.rb +48 -0
- data/lib/active_record/relation/predicate_builder/relation_handler.rb +13 -0
- data/lib/active_record/relation/predicate_builder.rb +135 -43
- data/lib/active_record/relation/query_methods.rb +928 -167
- data/lib/active_record/relation/spawn_methods.rb +48 -149
- data/lib/active_record/relation.rb +352 -207
- data/lib/active_record/result.rb +101 -10
- data/lib/active_record/runtime_registry.rb +22 -0
- data/lib/active_record/sanitization.rb +56 -59
- data/lib/active_record/schema.rb +19 -13
- data/lib/active_record/schema_dumper.rb +106 -63
- data/lib/active_record/schema_migration.rb +53 -0
- data/lib/active_record/scoping/default.rb +50 -57
- data/lib/active_record/scoping/named.rb +73 -109
- data/lib/active_record/scoping.rb +58 -123
- data/lib/active_record/serialization.rb +6 -2
- data/lib/active_record/serializers/xml_serializer.rb +12 -22
- data/lib/active_record/statement_cache.rb +111 -0
- data/lib/active_record/store.rb +168 -15
- data/lib/active_record/tasks/database_tasks.rb +299 -0
- data/lib/active_record/tasks/mysql_database_tasks.rb +159 -0
- data/lib/active_record/tasks/postgresql_database_tasks.rb +101 -0
- data/lib/active_record/tasks/sqlite_database_tasks.rb +55 -0
- data/lib/active_record/timestamp.rb +23 -16
- data/lib/active_record/transactions.rb +125 -79
- data/lib/active_record/type/big_integer.rb +13 -0
- data/lib/active_record/type/binary.rb +50 -0
- data/lib/active_record/type/boolean.rb +31 -0
- data/lib/active_record/type/date.rb +50 -0
- data/lib/active_record/type/date_time.rb +54 -0
- data/lib/active_record/type/decimal.rb +64 -0
- data/lib/active_record/type/decimal_without_scale.rb +11 -0
- data/lib/active_record/type/decorator.rb +14 -0
- data/lib/active_record/type/float.rb +19 -0
- data/lib/active_record/type/hash_lookup_type_map.rb +23 -0
- data/lib/active_record/type/integer.rb +59 -0
- data/lib/active_record/type/mutable.rb +16 -0
- data/lib/active_record/type/numeric.rb +36 -0
- data/lib/active_record/type/serialized.rb +62 -0
- data/lib/active_record/type/string.rb +40 -0
- data/lib/active_record/type/text.rb +11 -0
- data/lib/active_record/type/time.rb +26 -0
- data/lib/active_record/type/time_value.rb +38 -0
- data/lib/active_record/type/type_map.rb +64 -0
- data/lib/active_record/type/unsigned_integer.rb +15 -0
- data/lib/active_record/type/value.rb +110 -0
- data/lib/active_record/type.rb +23 -0
- data/lib/active_record/validations/associated.rb +24 -16
- data/lib/active_record/validations/presence.rb +67 -0
- data/lib/active_record/validations/uniqueness.rb +123 -64
- data/lib/active_record/validations.rb +36 -29
- data/lib/active_record/version.rb +5 -7
- data/lib/active_record.rb +66 -46
- data/lib/rails/generators/active_record/migration/migration_generator.rb +53 -8
- data/lib/rails/generators/active_record/{model/templates/migration.rb → migration/templates/create_table_migration.rb} +5 -1
- data/lib/rails/generators/active_record/migration/templates/migration.rb +20 -15
- data/lib/rails/generators/active_record/migration.rb +11 -8
- data/lib/rails/generators/active_record/model/model_generator.rb +9 -4
- data/lib/rails/generators/active_record/model/templates/model.rb +4 -6
- data/lib/rails/generators/active_record/model/templates/module.rb +1 -1
- data/lib/rails/generators/active_record.rb +3 -11
- metadata +101 -45
- data/examples/associations.png +0 -0
- data/lib/active_record/associations/has_and_belongs_to_many_association.rb +0 -63
- data/lib/active_record/associations/join_helper.rb +0 -55
- data/lib/active_record/associations/preloader/has_and_belongs_to_many.rb +0 -60
- data/lib/active_record/attribute_methods/deprecated_underscore_read.rb +0 -32
- data/lib/active_record/connection_adapters/abstract/connection_specification.rb +0 -191
- data/lib/active_record/connection_adapters/sqlite_adapter.rb +0 -583
- data/lib/active_record/dynamic_finder_match.rb +0 -68
- data/lib/active_record/dynamic_scope_match.rb +0 -23
- data/lib/active_record/fixtures/file.rb +0 -65
- data/lib/active_record/identity_map.rb +0 -162
- data/lib/active_record/observer.rb +0 -121
- data/lib/active_record/session_store.rb +0 -360
- data/lib/active_record/test_case.rb +0 -73
- data/lib/rails/generators/active_record/observer/observer_generator.rb +0 -15
- data/lib/rails/generators/active_record/observer/templates/observer.rb +0 -4
- data/lib/rails/generators/active_record/session_migration/session_migration_generator.rb +0 -25
- data/lib/rails/generators/active_record/session_migration/templates/migration.rb +0 -12
@@ -1,5 +1,3 @@
|
|
1
|
-
require 'active_support/concern'
|
2
|
-
|
3
1
|
module ActiveRecord
|
4
2
|
module ModelSchema
|
5
3
|
extend ActiveSupport::Concern
|
@@ -12,8 +10,7 @@ module ActiveRecord
|
|
12
10
|
# the Product class will look for "productid" instead of "id" as the primary column. If the
|
13
11
|
# latter is specified, the Product class will look for "product_id" instead of "id". Remember
|
14
12
|
# that this is a global setting for all Active Records.
|
15
|
-
|
16
|
-
self.primary_key_prefix_type = nil
|
13
|
+
mattr_accessor :primary_key_prefix_type, instance_writer: false
|
17
14
|
|
18
15
|
##
|
19
16
|
# :singleton-method:
|
@@ -25,23 +22,48 @@ module ActiveRecord
|
|
25
22
|
# If you are organising your models within modules you can add a prefix to the models within
|
26
23
|
# a namespace by defining a singleton method in the parent module called table_name_prefix which
|
27
24
|
# returns your chosen prefix.
|
28
|
-
class_attribute :table_name_prefix, :
|
25
|
+
class_attribute :table_name_prefix, instance_writer: false
|
29
26
|
self.table_name_prefix = ""
|
30
27
|
|
31
28
|
##
|
32
29
|
# :singleton-method:
|
33
30
|
# Works like +table_name_prefix+, but appends instead of prepends (set to "_basecamp" gives "projects_basecamp",
|
34
31
|
# "people_basecamp"). By default, the suffix is the empty string.
|
35
|
-
|
32
|
+
#
|
33
|
+
# If you are organising your models within modules, you can add a suffix to the models within
|
34
|
+
# a namespace by defining a singleton method in the parent module called table_name_suffix which
|
35
|
+
# returns your chosen suffix.
|
36
|
+
class_attribute :table_name_suffix, instance_writer: false
|
36
37
|
self.table_name_suffix = ""
|
37
38
|
|
39
|
+
##
|
40
|
+
# :singleton-method:
|
41
|
+
# Accessor for the name of the schema migrations table. By default, the value is "schema_migrations"
|
42
|
+
class_attribute :schema_migrations_table_name, instance_accessor: false
|
43
|
+
self.schema_migrations_table_name = "schema_migrations"
|
44
|
+
|
38
45
|
##
|
39
46
|
# :singleton-method:
|
40
47
|
# Indicates whether table names should be the pluralized versions of the corresponding class names.
|
41
48
|
# If true, the default table name for a Product class will be +products+. If false, it would just be +product+.
|
42
49
|
# See table_name for the full rules on table/class naming. This is true, by default.
|
43
|
-
class_attribute :pluralize_table_names, :
|
50
|
+
class_attribute :pluralize_table_names, instance_writer: false
|
44
51
|
self.pluralize_table_names = true
|
52
|
+
|
53
|
+
self.inheritance_column = 'type'
|
54
|
+
|
55
|
+
delegate :type_for_attribute, to: :class
|
56
|
+
end
|
57
|
+
|
58
|
+
# Derives the join table name for +first_table+ and +second_table+. The
|
59
|
+
# table names appear in alphabetical order. A common prefix is removed
|
60
|
+
# (useful for namespaced models like Music::Artist and Music::Record):
|
61
|
+
#
|
62
|
+
# artists, records => artists_records
|
63
|
+
# records, artists => artists_records
|
64
|
+
# music_artists, music_records => music_artists_records
|
65
|
+
def self.derive_join_table_name(first_table, second_table) # :nodoc:
|
66
|
+
[first_table.to_s, second_table.to_s].sort.join("\0").gsub(/^(.*_)(.+)\0\1(.+)/, '\1\2_\3').tr("\0", "_")
|
45
67
|
end
|
46
68
|
|
47
69
|
module ClassMethods
|
@@ -105,10 +127,6 @@ module ActiveRecord
|
|
105
127
|
@table_name
|
106
128
|
end
|
107
129
|
|
108
|
-
def original_table_name #:nodoc:
|
109
|
-
deprecated_original_property_getter :table_name
|
110
|
-
end
|
111
|
-
|
112
130
|
# Sets the table name explicitly. Example:
|
113
131
|
#
|
114
132
|
# class Project < ActiveRecord::Base
|
@@ -118,18 +136,18 @@ module ActiveRecord
|
|
118
136
|
# You can also just define your own <tt>self.table_name</tt> method; see
|
119
137
|
# the documentation for ActiveRecord::Base#table_name.
|
120
138
|
def table_name=(value)
|
121
|
-
|
122
|
-
|
123
|
-
@
|
124
|
-
|
125
|
-
|
126
|
-
|
139
|
+
value = value && value.to_s
|
140
|
+
|
141
|
+
if defined?(@table_name)
|
142
|
+
return if value == @table_name
|
143
|
+
reset_column_information if connected?
|
144
|
+
end
|
127
145
|
|
128
|
-
|
129
|
-
deprecated_property_setter :table_name, value, block
|
146
|
+
@table_name = value
|
130
147
|
@quoted_table_name = nil
|
131
148
|
@arel_table = nil
|
132
|
-
@
|
149
|
+
@sequence_name = nil unless defined?(@explicit_sequence_name) && @explicit_sequence_name
|
150
|
+
@relation = Relation.create(self, arel_table)
|
133
151
|
end
|
134
152
|
|
135
153
|
# Returns a quoted version of the table name, used to construct SQL statements.
|
@@ -139,16 +157,12 @@ module ActiveRecord
|
|
139
157
|
|
140
158
|
# Computes the table name, (re)sets it internally, and returns it.
|
141
159
|
def reset_table_name #:nodoc:
|
142
|
-
if abstract_class?
|
143
|
-
|
144
|
-
nil
|
145
|
-
else
|
146
|
-
superclass.table_name
|
147
|
-
end
|
160
|
+
self.table_name = if abstract_class?
|
161
|
+
superclass == Base ? nil : superclass.table_name
|
148
162
|
elsif superclass.abstract_class?
|
149
|
-
|
163
|
+
superclass.table_name || compute_table_name
|
150
164
|
else
|
151
|
-
|
165
|
+
compute_table_name
|
152
166
|
end
|
153
167
|
end
|
154
168
|
|
@@ -156,30 +170,29 @@ module ActiveRecord
|
|
156
170
|
(parents.detect{ |p| p.respond_to?(:table_name_prefix) } || self).table_name_prefix
|
157
171
|
end
|
158
172
|
|
159
|
-
|
160
|
-
|
161
|
-
if self == Base
|
162
|
-
(@inheritance_column ||= nil) || 'type'
|
163
|
-
else
|
164
|
-
(@inheritance_column ||= nil) || superclass.inheritance_column
|
165
|
-
end
|
173
|
+
def full_table_name_suffix #:nodoc:
|
174
|
+
(parents.detect {|p| p.respond_to?(:table_name_suffix) } || self).table_name_suffix
|
166
175
|
end
|
167
176
|
|
168
|
-
|
169
|
-
|
177
|
+
# Defines the name of the table column which will store the class name on single-table
|
178
|
+
# inheritance situations.
|
179
|
+
#
|
180
|
+
# The default inheritance column name is +type+, which means it's a
|
181
|
+
# reserved word inside Active Record. To be able to use single-table
|
182
|
+
# inheritance with another column name, or to use the column +type+ in
|
183
|
+
# your own model for something else, you can set +inheritance_column+:
|
184
|
+
#
|
185
|
+
# self.inheritance_column = 'zoink'
|
186
|
+
def inheritance_column
|
187
|
+
(@inheritance_column ||= nil) || superclass.inheritance_column
|
170
188
|
end
|
171
189
|
|
172
190
|
# Sets the value of inheritance_column
|
173
191
|
def inheritance_column=(value)
|
174
|
-
@
|
175
|
-
@inheritance_column = value.to_s
|
192
|
+
@inheritance_column = value.to_s
|
176
193
|
@explicit_inheritance_column = true
|
177
194
|
end
|
178
195
|
|
179
|
-
def set_inheritance_column(value = nil, &block) #:nodoc:
|
180
|
-
deprecated_property_setter :inheritance_column, value, block
|
181
|
-
end
|
182
|
-
|
183
196
|
def sequence_name
|
184
197
|
if base_class == self
|
185
198
|
@sequence_name ||= reset_sequence_name
|
@@ -188,12 +201,9 @@ module ActiveRecord
|
|
188
201
|
end
|
189
202
|
end
|
190
203
|
|
191
|
-
def original_sequence_name #:nodoc:
|
192
|
-
deprecated_original_property_getter :sequence_name
|
193
|
-
end
|
194
|
-
|
195
204
|
def reset_sequence_name #:nodoc:
|
196
|
-
|
205
|
+
@explicit_sequence_name = false
|
206
|
+
@sequence_name = connection.default_sequence_name(table_name, primary_key)
|
197
207
|
end
|
198
208
|
|
199
209
|
# Sets the name of the sequence to use when generating ids to the given
|
@@ -201,7 +211,7 @@ module ActiveRecord
|
|
201
211
|
# given block. This is required for Oracle and is useful for any
|
202
212
|
# database which relies on sequences for primary key generation.
|
203
213
|
#
|
204
|
-
# If a sequence name is not explicitly set when using Oracle
|
214
|
+
# If a sequence name is not explicitly set when using Oracle,
|
205
215
|
# it will default to the commonly used pattern of: #{table_name}_seq
|
206
216
|
#
|
207
217
|
# If a sequence name is not explicitly set when using PostgreSQL, it
|
@@ -211,12 +221,8 @@ module ActiveRecord
|
|
211
221
|
# self.sequence_name = "projectseq" # default would have been "project_seq"
|
212
222
|
# end
|
213
223
|
def sequence_name=(value)
|
214
|
-
@original_sequence_name = @sequence_name if defined?(@sequence_name)
|
215
224
|
@sequence_name = value.to_s
|
216
|
-
|
217
|
-
|
218
|
-
def set_sequence_name(value = nil, &block) #:nodoc:
|
219
|
-
deprecated_property_setter :sequence_name, value, block
|
225
|
+
@explicit_sequence_name = true
|
220
226
|
end
|
221
227
|
|
222
228
|
# Indicates whether the table associated with this class exists
|
@@ -224,24 +230,29 @@ module ActiveRecord
|
|
224
230
|
connection.schema_cache.table_exists?(table_name)
|
225
231
|
end
|
226
232
|
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
+
def attributes_builder # :nodoc:
|
234
|
+
@attributes_builder ||= AttributeSet::Builder.new(column_types, primary_key)
|
235
|
+
end
|
236
|
+
|
237
|
+
def column_types # :nodoc:
|
238
|
+
@column_types ||= columns_hash.transform_values(&:cast_type).tap do |h|
|
239
|
+
h.default = Type::Value.new
|
233
240
|
end
|
234
241
|
end
|
235
242
|
|
236
|
-
|
237
|
-
|
238
|
-
@columns_hash ||= Hash[columns.map { |c| [c.name, c] }]
|
243
|
+
def type_for_attribute(attr_name) # :nodoc:
|
244
|
+
column_types[attr_name]
|
239
245
|
end
|
240
246
|
|
241
247
|
# Returns a hash where the keys are column names and the values are
|
242
248
|
# default values when instantiating the AR object for this table.
|
243
249
|
def column_defaults
|
244
|
-
|
250
|
+
_default_attributes.dup.to_hash
|
251
|
+
end
|
252
|
+
|
253
|
+
def _default_attributes # :nodoc:
|
254
|
+
@default_attributes ||= attributes_builder.build_from_database(
|
255
|
+
raw_default_values)
|
245
256
|
end
|
246
257
|
|
247
258
|
# Returns an array of column names as strings.
|
@@ -252,21 +263,7 @@ module ActiveRecord
|
|
252
263
|
# Returns an array of column objects where the primary id, all columns ending in "_id" or "_count",
|
253
264
|
# and columns used for single table inheritance have been removed.
|
254
265
|
def content_columns
|
255
|
-
@content_columns ||= columns.reject { |c| c.
|
256
|
-
end
|
257
|
-
|
258
|
-
# Returns a hash of all the methods added to query each of the columns in the table with the name of the method as the key
|
259
|
-
# and true as the value. This makes it possible to do O(1) lookups in respond_to? to check if a given method for attribute
|
260
|
-
# is available.
|
261
|
-
def column_methods_hash #:nodoc:
|
262
|
-
@dynamic_methods_hash ||= column_names.inject(Hash.new(false)) do |methods, attr|
|
263
|
-
attr_name = attr.to_s
|
264
|
-
methods[attr.to_sym] = attr_name
|
265
|
-
methods["#{attr}=".to_sym] = attr_name
|
266
|
-
methods["#{attr}?".to_sym] = attr_name
|
267
|
-
methods["#{attr}_before_type_cast".to_sym] = attr_name
|
268
|
-
methods
|
269
|
-
end
|
266
|
+
@content_columns ||= columns.reject { |c| c.name == primary_key || c.name =~ /(_id|_count)$/ || c.name == inheritance_column }
|
270
267
|
end
|
271
268
|
|
272
269
|
# Resets all the cached information about columns, which will cause them
|
@@ -287,7 +284,7 @@ module ActiveRecord
|
|
287
284
|
#
|
288
285
|
# JobLevel.reset_column_information
|
289
286
|
# %w{assistant executive manager director}.each do |type|
|
290
|
-
# JobLevel.create(:
|
287
|
+
# JobLevel.create(name: type)
|
291
288
|
# end
|
292
289
|
# end
|
293
290
|
#
|
@@ -298,16 +295,17 @@ module ActiveRecord
|
|
298
295
|
def reset_column_information
|
299
296
|
connection.clear_cache!
|
300
297
|
undefine_attribute_methods
|
301
|
-
connection.schema_cache.clear_table_cache!(table_name)
|
298
|
+
connection.schema_cache.clear_table_cache!(table_name)
|
302
299
|
|
303
|
-
@
|
304
|
-
@
|
300
|
+
@arel_engine = nil
|
301
|
+
@column_names = nil
|
302
|
+
@column_types = nil
|
303
|
+
@content_columns = nil
|
304
|
+
@default_attributes = nil
|
305
305
|
@inheritance_column = nil unless defined?(@explicit_inheritance_column) && @explicit_inheritance_column
|
306
|
-
@
|
307
|
-
end
|
306
|
+
@relation = nil
|
308
307
|
|
309
|
-
|
310
|
-
connection.schema_cache.clear!
|
308
|
+
initialize_find_by_cache
|
311
309
|
end
|
312
310
|
|
313
311
|
private
|
@@ -315,8 +313,7 @@ module ActiveRecord
|
|
315
313
|
# Guesses the table name, but does not decorate it with prefix and suffix information.
|
316
314
|
def undecorated_table_name(class_name = base_class.name)
|
317
315
|
table_name = class_name.to_s.demodulize.underscore
|
318
|
-
|
319
|
-
table_name
|
316
|
+
pluralize_table_names ? table_name.pluralize : table_name
|
320
317
|
end
|
321
318
|
|
322
319
|
# Computes and returns a table name according to default conventions.
|
@@ -324,44 +321,21 @@ module ActiveRecord
|
|
324
321
|
base = base_class
|
325
322
|
if self == base
|
326
323
|
# Nested classes are prefixed with singular parent table name.
|
327
|
-
if parent <
|
324
|
+
if parent < Base && !parent.abstract_class?
|
328
325
|
contained = parent.table_name
|
329
326
|
contained = contained.singularize if parent.pluralize_table_names
|
330
327
|
contained += '_'
|
331
328
|
end
|
332
|
-
|
329
|
+
|
330
|
+
"#{full_table_name_prefix}#{contained}#{undecorated_table_name(name)}#{full_table_name_suffix}"
|
333
331
|
else
|
334
332
|
# STI subclasses always use their superclass' table.
|
335
333
|
base.table_name
|
336
334
|
end
|
337
335
|
end
|
338
336
|
|
339
|
-
def
|
340
|
-
|
341
|
-
ActiveSupport::Deprecation.warn(
|
342
|
-
"Calling set_#{property} is deprecated. If you need to lazily evaluate " \
|
343
|
-
"the #{property}, define your own `self.#{property}` class method. You can use `super` " \
|
344
|
-
"to get the default #{property} where you would have called `original_#{property}`."
|
345
|
-
)
|
346
|
-
|
347
|
-
define_attr_method property, value, false, &block
|
348
|
-
else
|
349
|
-
ActiveSupport::Deprecation.warn(
|
350
|
-
"Calling set_#{property} is deprecated. Please use `self.#{property} = 'the_name'` instead."
|
351
|
-
)
|
352
|
-
|
353
|
-
define_attr_method property, value, false
|
354
|
-
end
|
355
|
-
end
|
356
|
-
|
357
|
-
def deprecated_original_property_getter(property)
|
358
|
-
ActiveSupport::Deprecation.warn("original_#{property} is deprecated. Define self.#{property} and call super instead.")
|
359
|
-
|
360
|
-
if !instance_variable_defined?("@original_#{property}") && respond_to?("reset_#{property}")
|
361
|
-
send("reset_#{property}")
|
362
|
-
else
|
363
|
-
instance_variable_get("@original_#{property}")
|
364
|
-
end
|
337
|
+
def raw_default_values
|
338
|
+
columns_hash.transform_values(&:default)
|
365
339
|
end
|
366
340
|
end
|
367
341
|
end
|