activerecord 3.2.22.4 → 4.0.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of activerecord might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/CHANGELOG.md +2799 -617
- data/MIT-LICENSE +1 -1
- data/README.rdoc +23 -32
- data/examples/performance.rb +1 -1
- data/lib/active_record/aggregations.rb +40 -34
- data/lib/active_record/association_relation.rb +22 -0
- data/lib/active_record/associations/alias_tracker.rb +4 -2
- data/lib/active_record/associations/association.rb +60 -46
- data/lib/active_record/associations/association_scope.rb +46 -40
- data/lib/active_record/associations/belongs_to_association.rb +17 -4
- data/lib/active_record/associations/belongs_to_polymorphic_association.rb +1 -1
- data/lib/active_record/associations/builder/association.rb +81 -28
- data/lib/active_record/associations/builder/belongs_to.rb +73 -56
- data/lib/active_record/associations/builder/collection_association.rb +54 -40
- data/lib/active_record/associations/builder/has_and_belongs_to_many.rb +23 -41
- data/lib/active_record/associations/builder/has_many.rb +8 -64
- data/lib/active_record/associations/builder/has_one.rb +13 -50
- data/lib/active_record/associations/builder/singular_association.rb +13 -13
- data/lib/active_record/associations/collection_association.rb +130 -96
- data/lib/active_record/associations/collection_proxy.rb +916 -63
- data/lib/active_record/associations/has_and_belongs_to_many_association.rb +15 -13
- data/lib/active_record/associations/has_many_association.rb +35 -8
- data/lib/active_record/associations/has_many_through_association.rb +37 -17
- data/lib/active_record/associations/has_one_association.rb +42 -19
- data/lib/active_record/associations/has_one_through_association.rb +1 -1
- data/lib/active_record/associations/join_dependency/join_association.rb +39 -22
- data/lib/active_record/associations/join_dependency/join_base.rb +2 -2
- data/lib/active_record/associations/join_dependency/join_part.rb +21 -8
- data/lib/active_record/associations/join_dependency.rb +30 -9
- data/lib/active_record/associations/join_helper.rb +1 -11
- data/lib/active_record/associations/preloader/association.rb +29 -33
- data/lib/active_record/associations/preloader/collection_association.rb +1 -1
- data/lib/active_record/associations/preloader/has_and_belongs_to_many.rb +2 -2
- data/lib/active_record/associations/preloader/has_many_through.rb +6 -2
- data/lib/active_record/associations/preloader/has_one.rb +1 -1
- data/lib/active_record/associations/preloader/through_association.rb +13 -17
- data/lib/active_record/associations/preloader.rb +20 -43
- data/lib/active_record/associations/singular_association.rb +11 -11
- data/lib/active_record/associations/through_association.rb +3 -3
- data/lib/active_record/associations.rb +223 -282
- data/lib/active_record/attribute_assignment.rb +134 -154
- data/lib/active_record/attribute_methods/before_type_cast.rb +44 -5
- data/lib/active_record/attribute_methods/dirty.rb +36 -29
- data/lib/active_record/attribute_methods/primary_key.rb +45 -31
- data/lib/active_record/attribute_methods/query.rb +5 -4
- data/lib/active_record/attribute_methods/read.rb +67 -90
- data/lib/active_record/attribute_methods/serialization.rb +133 -70
- data/lib/active_record/attribute_methods/time_zone_conversion.rb +51 -45
- data/lib/active_record/attribute_methods/write.rb +34 -39
- data/lib/active_record/attribute_methods.rb +268 -108
- data/lib/active_record/autosave_association.rb +80 -73
- data/lib/active_record/base.rb +54 -451
- data/lib/active_record/callbacks.rb +60 -22
- data/lib/active_record/coders/yaml_column.rb +18 -21
- data/lib/active_record/connection_adapters/abstract/connection_pool.rb +347 -197
- data/lib/active_record/connection_adapters/abstract/database_limits.rb +9 -0
- data/lib/active_record/connection_adapters/abstract/database_statements.rb +146 -138
- data/lib/active_record/connection_adapters/abstract/query_cache.rb +25 -19
- data/lib/active_record/connection_adapters/abstract/quoting.rb +19 -3
- data/lib/active_record/connection_adapters/abstract/schema_definitions.rb +151 -142
- data/lib/active_record/connection_adapters/abstract/schema_dumper.rb +70 -0
- data/lib/active_record/connection_adapters/abstract/schema_statements.rb +499 -217
- data/lib/active_record/connection_adapters/abstract/transaction.rb +208 -0
- data/lib/active_record/connection_adapters/abstract_adapter.rb +209 -44
- data/lib/active_record/connection_adapters/abstract_mysql_adapter.rb +169 -61
- data/lib/active_record/connection_adapters/column.rb +67 -36
- data/lib/active_record/connection_adapters/connection_specification.rb +96 -0
- data/lib/active_record/connection_adapters/mysql2_adapter.rb +28 -29
- data/lib/active_record/connection_adapters/mysql_adapter.rb +200 -73
- data/lib/active_record/connection_adapters/postgresql/array_parser.rb +98 -0
- data/lib/active_record/connection_adapters/postgresql/cast.rb +160 -0
- data/lib/active_record/connection_adapters/postgresql/database_statements.rb +240 -0
- data/lib/active_record/connection_adapters/postgresql/oid.rb +374 -0
- data/lib/active_record/connection_adapters/postgresql/quoting.rb +183 -0
- data/lib/active_record/connection_adapters/postgresql/referential_integrity.rb +30 -0
- data/lib/active_record/connection_adapters/postgresql/schema_statements.rb +508 -0
- data/lib/active_record/connection_adapters/postgresql_adapter.rb +544 -899
- data/lib/active_record/connection_adapters/schema_cache.rb +76 -16
- data/lib/active_record/connection_adapters/sqlite3_adapter.rb +595 -16
- data/lib/active_record/connection_handling.rb +98 -0
- data/lib/active_record/core.rb +472 -0
- data/lib/active_record/counter_cache.rb +107 -108
- data/lib/active_record/dynamic_matchers.rb +115 -63
- data/lib/active_record/errors.rb +36 -18
- data/lib/active_record/explain.rb +15 -63
- data/lib/active_record/explain_registry.rb +30 -0
- data/lib/active_record/explain_subscriber.rb +8 -4
- data/lib/active_record/fixture_set/file.rb +55 -0
- data/lib/active_record/fixtures.rb +159 -155
- data/lib/active_record/inheritance.rb +93 -59
- data/lib/active_record/integration.rb +8 -8
- data/lib/active_record/locale/en.yml +8 -1
- data/lib/active_record/locking/optimistic.rb +39 -43
- data/lib/active_record/locking/pessimistic.rb +4 -4
- data/lib/active_record/log_subscriber.rb +19 -9
- data/lib/active_record/migration/command_recorder.rb +102 -33
- data/lib/active_record/migration/join_table.rb +15 -0
- data/lib/active_record/migration.rb +411 -173
- data/lib/active_record/model_schema.rb +81 -94
- data/lib/active_record/nested_attributes.rb +173 -131
- data/lib/active_record/null_relation.rb +67 -0
- data/lib/active_record/persistence.rb +254 -106
- data/lib/active_record/query_cache.rb +18 -36
- data/lib/active_record/querying.rb +19 -15
- data/lib/active_record/railtie.rb +113 -38
- 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 +115 -368
- data/lib/active_record/railties/jdbcmysql_error.rb +1 -1
- data/lib/active_record/readonly_attributes.rb +7 -3
- data/lib/active_record/reflection.rb +110 -61
- data/lib/active_record/relation/batches.rb +29 -29
- data/lib/active_record/relation/calculations.rb +155 -125
- data/lib/active_record/relation/delegation.rb +94 -18
- data/lib/active_record/relation/finder_methods.rb +151 -203
- data/lib/active_record/relation/merger.rb +188 -0
- data/lib/active_record/relation/predicate_builder.rb +85 -42
- data/lib/active_record/relation/query_methods.rb +793 -146
- data/lib/active_record/relation/spawn_methods.rb +43 -150
- data/lib/active_record/relation.rb +293 -173
- data/lib/active_record/result.rb +48 -7
- data/lib/active_record/runtime_registry.rb +17 -0
- data/lib/active_record/sanitization.rb +41 -54
- data/lib/active_record/schema.rb +19 -12
- data/lib/active_record/schema_dumper.rb +41 -41
- data/lib/active_record/schema_migration.rb +46 -0
- data/lib/active_record/scoping/default.rb +56 -52
- data/lib/active_record/scoping/named.rb +78 -103
- data/lib/active_record/scoping.rb +54 -124
- data/lib/active_record/serialization.rb +6 -2
- data/lib/active_record/serializers/xml_serializer.rb +9 -15
- data/lib/active_record/statement_cache.rb +26 -0
- data/lib/active_record/store.rb +131 -15
- data/lib/active_record/tasks/database_tasks.rb +204 -0
- data/lib/active_record/tasks/firebird_database_tasks.rb +56 -0
- data/lib/active_record/tasks/mysql_database_tasks.rb +144 -0
- data/lib/active_record/tasks/oracle_database_tasks.rb +45 -0
- data/lib/active_record/tasks/postgresql_database_tasks.rb +90 -0
- data/lib/active_record/tasks/sqlite_database_tasks.rb +51 -0
- data/lib/active_record/tasks/sqlserver_database_tasks.rb +48 -0
- data/lib/active_record/test_case.rb +67 -38
- data/lib/active_record/timestamp.rb +16 -11
- data/lib/active_record/transactions.rb +73 -51
- data/lib/active_record/validations/associated.rb +19 -13
- data/lib/active_record/validations/presence.rb +65 -0
- data/lib/active_record/validations/uniqueness.rb +110 -57
- data/lib/active_record/validations.rb +18 -17
- data/lib/active_record/version.rb +7 -6
- data/lib/active_record.rb +63 -45
- data/lib/rails/generators/active_record/migration/migration_generator.rb +45 -8
- data/lib/rails/generators/active_record/{model/templates/migration.rb → migration/templates/create_table_migration.rb} +4 -0
- data/lib/rails/generators/active_record/migration/templates/migration.rb +20 -15
- data/lib/rails/generators/active_record/model/model_generator.rb +5 -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 -5
- metadata +43 -29
- data/examples/associations.png +0 -0
- 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/rails/generators/active_record/migration.rb +0 -15
- 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,57 +1,39 @@
|
|
1
1
|
module ActiveRecord::Associations::Builder
|
2
2
|
class HasAndBelongsToMany < CollectionAssociation #:nodoc:
|
3
|
-
|
3
|
+
def macro
|
4
|
+
:has_and_belongs_to_many
|
5
|
+
end
|
4
6
|
|
5
|
-
|
7
|
+
def valid_options
|
8
|
+
super + [:join_table, :association_foreign_key, :delete_sql, :insert_sql]
|
9
|
+
end
|
6
10
|
|
7
11
|
def build
|
8
12
|
reflection = super
|
9
|
-
check_validity(reflection)
|
10
13
|
define_destroy_hook
|
11
14
|
reflection
|
12
15
|
end
|
13
16
|
|
14
|
-
|
17
|
+
def show_deprecation_warnings
|
18
|
+
super
|
15
19
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
class_eval <<-RUBY, __FILE__, __LINE__ + 1
|
20
|
-
def destroy_associations
|
21
|
-
association(#{name.to_sym.inspect}).delete_all_on_destroy
|
22
|
-
super
|
23
|
-
end
|
24
|
-
RUBY
|
25
|
-
})
|
26
|
-
end
|
27
|
-
|
28
|
-
# TODO: These checks should probably be moved into the Reflection, and we should not be
|
29
|
-
# redefining the options[:join_table] value - instead we should define a
|
30
|
-
# reflection.join_table method.
|
31
|
-
def check_validity(reflection)
|
32
|
-
if reflection.association_foreign_key == reflection.foreign_key
|
33
|
-
raise ActiveRecord::HasAndBelongsToManyAssociationForeignKeyNeeded.new(reflection)
|
20
|
+
[:delete_sql, :insert_sql].each do |name|
|
21
|
+
if options.include? name
|
22
|
+
ActiveSupport::Deprecation.warn("The :#{name} association option is deprecated. Please find an alternative (such as using has_many :through).")
|
34
23
|
end
|
35
|
-
|
36
|
-
reflection.options[:join_table] ||= join_table_name(
|
37
|
-
model.send(:undecorated_table_name, model.to_s),
|
38
|
-
model.send(:undecorated_table_name, reflection.class_name)
|
39
|
-
)
|
40
24
|
end
|
25
|
+
end
|
41
26
|
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
model.table_name_prefix + join_table + model.table_name_suffix
|
55
|
-
end
|
27
|
+
def define_destroy_hook
|
28
|
+
name = self.name
|
29
|
+
model.send(:include, Module.new {
|
30
|
+
class_eval <<-RUBY, __FILE__, __LINE__ + 1
|
31
|
+
def destroy_associations
|
32
|
+
association(:#{name}).delete_all
|
33
|
+
super
|
34
|
+
end
|
35
|
+
RUBY
|
36
|
+
})
|
37
|
+
end
|
56
38
|
end
|
57
39
|
end
|
@@ -1,71 +1,15 @@
|
|
1
|
-
require 'active_support/core_ext/object/inclusion'
|
2
|
-
|
3
1
|
module ActiveRecord::Associations::Builder
|
4
2
|
class HasMany < CollectionAssociation #:nodoc:
|
5
|
-
|
6
|
-
|
7
|
-
self.valid_options += [:primary_key, :dependent, :as, :through, :source, :source_type, :inverse_of]
|
8
|
-
|
9
|
-
def build
|
10
|
-
reflection = super
|
11
|
-
configure_dependency
|
12
|
-
reflection
|
3
|
+
def macro
|
4
|
+
:has_many
|
13
5
|
end
|
14
6
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
if options[:dependent]
|
19
|
-
unless options[:dependent].in?([:destroy, :delete_all, :nullify, :restrict])
|
20
|
-
raise ArgumentError, "The :dependent option expects either :destroy, :delete_all, " \
|
21
|
-
":nullify or :restrict (#{options[:dependent].inspect})"
|
22
|
-
end
|
23
|
-
|
24
|
-
send("define_#{options[:dependent]}_dependency_method")
|
25
|
-
model.before_destroy dependency_method_name
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
def define_destroy_dependency_method
|
30
|
-
name = self.name
|
31
|
-
mixin.redefine_method(dependency_method_name) do
|
32
|
-
send(name).each do |o|
|
33
|
-
# No point in executing the counter update since we're going to destroy the parent anyway
|
34
|
-
counter_method = ('belongs_to_counter_cache_before_destroy_for_' + self.class.name.downcase).to_sym
|
35
|
-
if o.respond_to?(counter_method)
|
36
|
-
class << o
|
37
|
-
self
|
38
|
-
end.send(:define_method, counter_method, Proc.new {})
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
send(name).delete_all
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|
46
|
-
def define_delete_all_dependency_method
|
47
|
-
name = self.name
|
48
|
-
mixin.redefine_method(dependency_method_name) do
|
49
|
-
association(name).delete_all_on_destroy
|
50
|
-
end
|
51
|
-
end
|
52
|
-
|
53
|
-
def define_nullify_dependency_method
|
54
|
-
name = self.name
|
55
|
-
mixin.redefine_method(dependency_method_name) do
|
56
|
-
send(name).delete_all
|
57
|
-
end
|
58
|
-
end
|
59
|
-
|
60
|
-
def define_restrict_dependency_method
|
61
|
-
name = self.name
|
62
|
-
mixin.redefine_method(dependency_method_name) do
|
63
|
-
raise ActiveRecord::DeleteRestrictionError.new(name) unless send(name).empty?
|
64
|
-
end
|
65
|
-
end
|
7
|
+
def valid_options
|
8
|
+
super + [:primary_key, :dependent, :as, :through, :source, :source_type, :inverse_of, :counter_cache]
|
9
|
+
end
|
66
10
|
|
67
|
-
|
68
|
-
|
69
|
-
|
11
|
+
def valid_dependent_options
|
12
|
+
[:destroy, :delete_all, :nullify, :restrict, :restrict_with_error, :restrict_with_exception]
|
13
|
+
end
|
70
14
|
end
|
71
15
|
end
|
@@ -1,62 +1,25 @@
|
|
1
|
-
require 'active_support/core_ext/object/inclusion'
|
2
|
-
|
3
1
|
module ActiveRecord::Associations::Builder
|
4
2
|
class HasOne < SingularAssociation #:nodoc:
|
5
|
-
|
6
|
-
|
7
|
-
|
3
|
+
def macro
|
4
|
+
:has_one
|
5
|
+
end
|
8
6
|
|
9
|
-
|
10
|
-
|
7
|
+
def valid_options
|
8
|
+
valid = super + [:order, :as]
|
9
|
+
valid += [:through, :source, :source_type] if options[:through]
|
10
|
+
valid
|
11
|
+
end
|
11
12
|
|
12
13
|
def constructable?
|
13
14
|
!options[:through]
|
14
15
|
end
|
15
16
|
|
16
|
-
def
|
17
|
-
|
18
|
-
configure_dependency unless options[:through]
|
19
|
-
reflection
|
17
|
+
def configure_dependency
|
18
|
+
super unless options[:through]
|
20
19
|
end
|
21
20
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
valid_options = self.class.valid_options
|
26
|
-
valid_options += self.class.through_options if options[:through]
|
27
|
-
options.assert_valid_keys(valid_options)
|
28
|
-
end
|
29
|
-
|
30
|
-
def configure_dependency
|
31
|
-
if options[:dependent]
|
32
|
-
unless options[:dependent].in?([:destroy, :delete, :nullify, :restrict])
|
33
|
-
raise ArgumentError, "The :dependent option expects either :destroy, :delete, " \
|
34
|
-
":nullify or :restrict (#{options[:dependent].inspect})"
|
35
|
-
end
|
36
|
-
|
37
|
-
send("define_#{options[:dependent]}_dependency_method")
|
38
|
-
model.before_destroy dependency_method_name
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
def dependency_method_name
|
43
|
-
"has_one_dependent_#{options[:dependent]}_for_#{name}"
|
44
|
-
end
|
45
|
-
|
46
|
-
def define_destroy_dependency_method
|
47
|
-
name = self.name
|
48
|
-
mixin.redefine_method(dependency_method_name) do
|
49
|
-
association(name).delete
|
50
|
-
end
|
51
|
-
end
|
52
|
-
alias :define_delete_dependency_method :define_destroy_dependency_method
|
53
|
-
alias :define_nullify_dependency_method :define_destroy_dependency_method
|
54
|
-
|
55
|
-
def define_restrict_dependency_method
|
56
|
-
name = self.name
|
57
|
-
mixin.redefine_method(dependency_method_name) do
|
58
|
-
raise ActiveRecord::DeleteRestrictionError.new(name) unless send(name).nil?
|
59
|
-
end
|
60
|
-
end
|
21
|
+
def valid_dependent_options
|
22
|
+
[:destroy, :delete, :nullify, :restrict, :restrict_with_error, :restrict_with_exception]
|
23
|
+
end
|
61
24
|
end
|
62
25
|
end
|
@@ -1,6 +1,8 @@
|
|
1
1
|
module ActiveRecord::Associations::Builder
|
2
2
|
class SingularAssociation < Association #:nodoc:
|
3
|
-
|
3
|
+
def valid_options
|
4
|
+
super + [:remote, :dependent, :primary_key, :inverse_of]
|
5
|
+
end
|
4
6
|
|
5
7
|
def constructable?
|
6
8
|
true
|
@@ -11,22 +13,20 @@ module ActiveRecord::Associations::Builder
|
|
11
13
|
define_constructors if constructable?
|
12
14
|
end
|
13
15
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
mixin.redefine_method("build_#{name}") do |*params, &block|
|
20
|
-
association(name).build(*params, &block)
|
16
|
+
def define_constructors
|
17
|
+
mixin.class_eval <<-CODE, __FILE__, __LINE__ + 1
|
18
|
+
def build_#{name}(*args, &block)
|
19
|
+
association(:#{name}).build(*args, &block)
|
21
20
|
end
|
22
21
|
|
23
|
-
|
24
|
-
association(name).create(*
|
22
|
+
def create_#{name}(*args, &block)
|
23
|
+
association(:#{name}).create(*args, &block)
|
25
24
|
end
|
26
25
|
|
27
|
-
|
28
|
-
association(name).create!(*
|
26
|
+
def create_#{name}!(*args, &block)
|
27
|
+
association(:#{name}).create!(*args, &block)
|
29
28
|
end
|
30
|
-
|
29
|
+
CODE
|
30
|
+
end
|
31
31
|
end
|
32
32
|
end
|