activerecord 5.0.0.beta3 → 5.0.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 +225 -8
- data/examples/performance.rb +0 -1
- data/examples/simple.rb +0 -1
- data/lib/active_record.rb +0 -1
- data/lib/active_record/associations.rb +10 -6
- data/lib/active_record/associations/association.rb +1 -1
- data/lib/active_record/associations/builder/collection_association.rb +5 -1
- data/lib/active_record/associations/join_dependency.rb +1 -1
- data/lib/active_record/associations/preloader.rb +1 -0
- data/lib/active_record/associations/preloader/through_association.rb +15 -8
- data/lib/active_record/attribute/user_provided_default.rb +10 -5
- data/lib/active_record/attribute_methods/time_zone_conversion.rb +1 -1
- data/lib/active_record/attributes.rb +3 -3
- data/lib/active_record/autosave_association.rb +1 -1
- data/lib/active_record/base.rb +2 -1
- data/lib/active_record/collection_cache_key.rb +1 -1
- data/lib/active_record/connection_adapters/abstract/connection_pool.rb +0 -19
- data/lib/active_record/connection_adapters/abstract/database_statements.rb +7 -8
- data/lib/active_record/connection_adapters/abstract/query_cache.rb +1 -1
- data/lib/active_record/connection_adapters/abstract/quoting.rb +7 -1
- data/lib/active_record/connection_adapters/abstract/savepoints.rb +3 -3
- data/lib/active_record/connection_adapters/abstract/schema_creation.rb +16 -2
- data/lib/active_record/connection_adapters/abstract/schema_definitions.rb +9 -4
- data/lib/active_record/connection_adapters/abstract/schema_dumper.rb +20 -10
- data/lib/active_record/connection_adapters/abstract/schema_statements.rb +85 -20
- data/lib/active_record/connection_adapters/abstract/transaction.rb +13 -1
- data/lib/active_record/connection_adapters/abstract_adapter.rb +37 -16
- data/lib/active_record/connection_adapters/abstract_mysql_adapter.rb +119 -108
- data/lib/active_record/connection_adapters/column.rb +5 -6
- data/lib/active_record/connection_adapters/mysql/database_statements.rb +125 -0
- data/lib/active_record/connection_adapters/mysql/quoting.rb +51 -0
- data/lib/active_record/connection_adapters/mysql/schema_creation.rb +27 -6
- data/lib/active_record/connection_adapters/mysql/schema_dumper.rb +8 -13
- data/lib/active_record/connection_adapters/mysql2_adapter.rb +18 -55
- data/lib/active_record/connection_adapters/postgresql/column.rb +0 -1
- data/lib/active_record/connection_adapters/postgresql/oid/cidr.rb +2 -0
- data/lib/active_record/connection_adapters/postgresql/quoting.rb +4 -4
- data/lib/active_record/connection_adapters/postgresql/schema_dumper.rb +7 -10
- data/lib/active_record/connection_adapters/postgresql/schema_statements.rb +65 -25
- data/lib/active_record/connection_adapters/postgresql_adapter.rb +59 -30
- data/lib/active_record/connection_adapters/sqlite3/quoting.rb +48 -0
- data/lib/active_record/connection_adapters/sqlite3/schema_creation.rb +7 -0
- data/lib/active_record/connection_adapters/sqlite3_adapter.rb +19 -56
- data/lib/active_record/connection_adapters/statement_pool.rb +6 -4
- data/lib/active_record/core.rb +13 -4
- data/lib/active_record/enum.rb +1 -1
- data/lib/active_record/errors.rb +9 -0
- data/lib/active_record/fixture_set/file.rb +7 -1
- data/lib/active_record/gem_version.rb +1 -1
- data/lib/active_record/locking/optimistic.rb +4 -0
- data/lib/active_record/log_subscriber.rb +1 -1
- data/lib/active_record/migration.rb +4 -4
- data/lib/active_record/migration/compatibility.rb +1 -1
- data/lib/active_record/model_schema.rb +12 -0
- data/lib/active_record/nested_attributes.rb +1 -1
- data/lib/active_record/persistence.rb +1 -1
- data/lib/active_record/query_cache.rb +13 -16
- data/lib/active_record/querying.rb +1 -1
- data/lib/active_record/railtie.rb +8 -11
- data/lib/active_record/railties/databases.rake +5 -5
- data/lib/active_record/reflection.rb +21 -4
- data/lib/active_record/relation.rb +10 -10
- data/lib/active_record/relation/batches.rb +29 -9
- data/lib/active_record/relation/delegation.rb +0 -1
- data/lib/active_record/relation/finder_methods.rb +27 -8
- data/lib/active_record/relation/predicate_builder.rb +4 -2
- data/lib/active_record/relation/where_clause.rb +2 -1
- data/lib/active_record/schema_dumper.rb +39 -24
- data/lib/active_record/scoping/default.rb +2 -1
- data/lib/active_record/suppressor.rb +5 -1
- data/lib/active_record/tasks/database_tasks.rb +6 -4
- data/lib/active_record/tasks/mysql_database_tasks.rb +1 -1
- data/lib/active_record/type.rb +1 -1
- data/lib/active_record/type/internal/abstract_json.rb +1 -5
- data/lib/active_record/type/time.rb +12 -0
- data/lib/active_record/validations/uniqueness.rb +1 -4
- data/lib/rails/generators/active_record/model/model_generator.rb +15 -11
- data/lib/rails/generators/active_record/model/templates/application_record.rb +2 -0
- metadata +11 -8
@@ -115,7 +115,8 @@ module ActiveRecord
|
|
115
115
|
base_rel ||= relation
|
116
116
|
evaluate_default_scope do
|
117
117
|
default_scopes.inject(base_rel) do |default_scope, scope|
|
118
|
-
|
118
|
+
scope = scope.respond_to?(:to_proc) ? scope : scope.method(:call)
|
119
|
+
default_scope.merge(base_rel.instance_exec(&scope))
|
119
120
|
end
|
120
121
|
end
|
121
122
|
end
|
@@ -37,7 +37,11 @@ module ActiveRecord
|
|
37
37
|
end
|
38
38
|
end
|
39
39
|
|
40
|
-
def
|
40
|
+
def save(*) # :nodoc:
|
41
|
+
SuppressorRegistry.suppressed[self.class.name] ? true : super
|
42
|
+
end
|
43
|
+
|
44
|
+
def save!(*) # :nodoc:
|
41
45
|
SuppressorRegistry.suppressed[self.class.name] ? true : super
|
42
46
|
end
|
43
47
|
end
|
@@ -107,8 +107,9 @@ module ActiveRecord
|
|
107
107
|
def create(*arguments)
|
108
108
|
configuration = arguments.first
|
109
109
|
class_for_adapter(configuration['adapter']).new(*arguments).create
|
110
|
+
$stdout.puts "Created database '#{configuration['database']}'"
|
110
111
|
rescue DatabaseAlreadyExists
|
111
|
-
$stderr.puts "#{configuration['database']} already exists"
|
112
|
+
$stderr.puts "Database '#{configuration['database']}' already exists"
|
112
113
|
rescue Exception => error
|
113
114
|
$stderr.puts error
|
114
115
|
$stderr.puts "Couldn't create database for #{configuration.inspect}"
|
@@ -133,11 +134,12 @@ module ActiveRecord
|
|
133
134
|
def drop(*arguments)
|
134
135
|
configuration = arguments.first
|
135
136
|
class_for_adapter(configuration['adapter']).new(*arguments).drop
|
137
|
+
$stdout.puts "Dropped database '#{configuration['database']}'"
|
136
138
|
rescue ActiveRecord::NoDatabaseError
|
137
139
|
$stderr.puts "Database '#{configuration['database']}' does not exist"
|
138
140
|
rescue Exception => error
|
139
141
|
$stderr.puts error
|
140
|
-
$stderr.puts "Couldn't drop #{configuration['database']}"
|
142
|
+
$stderr.puts "Couldn't drop database '#{configuration['database']}'"
|
141
143
|
raise
|
142
144
|
end
|
143
145
|
|
@@ -159,6 +161,7 @@ module ActiveRecord
|
|
159
161
|
Migrator.migrate(migrations_paths, version) do |migration|
|
160
162
|
scope.blank? || scope == migration.scope
|
161
163
|
end
|
164
|
+
ActiveRecord::Base.clear_cache!
|
162
165
|
ensure
|
163
166
|
Migration.verbose = verbose_was
|
164
167
|
end
|
@@ -282,8 +285,7 @@ module ActiveRecord
|
|
282
285
|
|
283
286
|
def each_current_configuration(environment)
|
284
287
|
environments = [environment]
|
285
|
-
|
286
|
-
environments << 'test' if environment == 'development' && ENV['RAILS_ENV'].nil?
|
288
|
+
environments << 'test' if environment == 'development'
|
287
289
|
|
288
290
|
configurations = ActiveRecord::Base.configurations.values_at(*environments)
|
289
291
|
configurations.compact.each do |configuration|
|
@@ -130,7 +130,7 @@ IDENTIFIED BY '#{configuration['password']}' WITH GRANT OPTION;
|
|
130
130
|
'sslca' => '--ssl-ca',
|
131
131
|
'sslcert' => '--ssl-cert',
|
132
132
|
'sslcapath' => '--ssl-capath',
|
133
|
-
'sslcipher' => '--
|
133
|
+
'sslcipher' => '--ssl-cipher',
|
134
134
|
'sslkey' => '--ssl-key'
|
135
135
|
}.map { |opt, arg| "#{arg}=#{configuration[opt]}" if configuration[opt] }.compact
|
136
136
|
|
data/lib/active_record/type.rb
CHANGED
@@ -61,7 +61,7 @@ module ActiveRecord
|
|
61
61
|
register(:binary, Type::Binary, override: false)
|
62
62
|
register(:boolean, Type::Boolean, override: false)
|
63
63
|
register(:date, Type::Date, override: false)
|
64
|
-
register(:
|
64
|
+
register(:datetime, Type::DateTime, override: false)
|
65
65
|
register(:decimal, Type::Decimal, override: false)
|
66
66
|
register(:float, Type::Float, override: false)
|
67
67
|
register(:integer, Type::Integer, override: false)
|
@@ -2,6 +2,18 @@ module ActiveRecord
|
|
2
2
|
module Type
|
3
3
|
class Time < ActiveModel::Type::Time
|
4
4
|
include Internal::Timezone
|
5
|
+
|
6
|
+
class Value < DelegateClass(::Time) # :nodoc:
|
7
|
+
end
|
8
|
+
|
9
|
+
def serialize(value)
|
10
|
+
case value = super
|
11
|
+
when ::Time
|
12
|
+
Value.new(value)
|
13
|
+
else
|
14
|
+
value
|
15
|
+
end
|
16
|
+
end
|
5
17
|
end
|
6
18
|
end
|
7
19
|
end
|
@@ -18,7 +18,7 @@ module ActiveRecord
|
|
18
18
|
relation = build_relation(finder_class, table, attribute, value)
|
19
19
|
if record.persisted?
|
20
20
|
if finder_class.primary_key
|
21
|
-
relation = relation.where.not(finder_class.primary_key => record.id_was)
|
21
|
+
relation = relation.where.not(finder_class.primary_key => record.id_was || record.id)
|
22
22
|
else
|
23
23
|
raise UnknownPrimaryKey.new(finder_class, "Can not validate uniqueness for persisted record without primary key.")
|
24
24
|
end
|
@@ -67,9 +67,6 @@ module ActiveRecord
|
|
67
67
|
cast_type = klass.type_for_attribute(attribute_name)
|
68
68
|
value = cast_type.serialize(value)
|
69
69
|
value = klass.connection.type_cast(value)
|
70
|
-
if value.is_a?(String) && column.limit
|
71
|
-
value = value.to_s[0, column.limit]
|
72
|
-
end
|
73
70
|
|
74
71
|
comparison = if !options[:case_sensitive] && !value.nil?
|
75
72
|
# will use SQL LOWER function before comparison, unless it detects a case insensitive collation
|
@@ -41,8 +41,8 @@ module ActiveRecord
|
|
41
41
|
|
42
42
|
# FIXME: Change this file to a symlink once RubyGems 2.5.0 is required.
|
43
43
|
def generate_application_record
|
44
|
-
if self.behavior == :invoke && !
|
45
|
-
template 'application_record.rb',
|
44
|
+
if self.behavior == :invoke && !application_record_exist?
|
45
|
+
template 'application_record.rb', application_record_file_name
|
46
46
|
end
|
47
47
|
end
|
48
48
|
|
@@ -51,18 +51,22 @@ module ActiveRecord
|
|
51
51
|
options[:parent] || determine_default_parent_class
|
52
52
|
end
|
53
53
|
|
54
|
-
def
|
55
|
-
|
54
|
+
def application_record_exist?
|
55
|
+
file_exist = nil
|
56
|
+
in_root { file_exist = File.exist?(application_record_file_name) }
|
57
|
+
file_exist
|
58
|
+
end
|
56
59
|
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
end
|
60
|
+
def application_record_file_name
|
61
|
+
@application_record_file_name ||= if mountable_engine?
|
62
|
+
"app/models/#{namespaced_path}/application_record.rb"
|
63
|
+
else
|
64
|
+
'app/models/application_record.rb'
|
63
65
|
end
|
66
|
+
end
|
64
67
|
|
65
|
-
|
68
|
+
def determine_default_parent_class
|
69
|
+
if application_record_exist?
|
66
70
|
"ApplicationRecord"
|
67
71
|
else
|
68
72
|
"ActiveRecord::Base"
|
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.0.
|
4
|
+
version: 5.0.0.beta4
|
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: 2016-
|
11
|
+
date: 2016-04-27 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.0.
|
19
|
+
version: 5.0.0.beta4
|
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.0.
|
26
|
+
version: 5.0.0.beta4
|
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.0.
|
33
|
+
version: 5.0.0.beta4
|
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.0.
|
40
|
+
version: 5.0.0.beta4
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: arel
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -145,7 +145,9 @@ files:
|
|
145
145
|
- lib/active_record/connection_adapters/connection_specification.rb
|
146
146
|
- lib/active_record/connection_adapters/determine_if_preparable_visitor.rb
|
147
147
|
- lib/active_record/connection_adapters/mysql/column.rb
|
148
|
+
- lib/active_record/connection_adapters/mysql/database_statements.rb
|
148
149
|
- lib/active_record/connection_adapters/mysql/explain_pretty_printer.rb
|
150
|
+
- lib/active_record/connection_adapters/mysql/quoting.rb
|
149
151
|
- lib/active_record/connection_adapters/mysql/schema_creation.rb
|
150
152
|
- lib/active_record/connection_adapters/mysql/schema_definitions.rb
|
151
153
|
- lib/active_record/connection_adapters/mysql/schema_dumper.rb
|
@@ -187,6 +189,7 @@ files:
|
|
187
189
|
- lib/active_record/connection_adapters/schema_cache.rb
|
188
190
|
- lib/active_record/connection_adapters/sql_type_metadata.rb
|
189
191
|
- lib/active_record/connection_adapters/sqlite3/explain_pretty_printer.rb
|
192
|
+
- lib/active_record/connection_adapters/sqlite3/quoting.rb
|
190
193
|
- lib/active_record/connection_adapters/sqlite3/schema_creation.rb
|
191
194
|
- lib/active_record/connection_adapters/sqlite3_adapter.rb
|
192
195
|
- lib/active_record/connection_adapters/statement_pool.rb
|
@@ -303,7 +306,7 @@ files:
|
|
303
306
|
- lib/rails/generators/active_record/model/templates/application_record.rb
|
304
307
|
- lib/rails/generators/active_record/model/templates/model.rb
|
305
308
|
- lib/rails/generators/active_record/model/templates/module.rb
|
306
|
-
homepage: http://
|
309
|
+
homepage: http://rubyonrails.org
|
307
310
|
licenses:
|
308
311
|
- MIT
|
309
312
|
metadata: {}
|
@@ -325,7 +328,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
325
328
|
version: 1.3.1
|
326
329
|
requirements: []
|
327
330
|
rubyforge_project:
|
328
|
-
rubygems_version: 2.
|
331
|
+
rubygems_version: 2.6.4
|
329
332
|
signing_key:
|
330
333
|
specification_version: 4
|
331
334
|
summary: Object-relational mapper framework (part of Rails).
|