activerecord 4.0.0 → 4.0.1.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 +326 -3
- data/README.rdoc +1 -1
- data/lib/active_record.rb +1 -0
- data/lib/active_record/association_relation.rb +18 -0
- data/lib/active_record/associations/association.rb +11 -3
- data/lib/active_record/associations/builder/belongs_to.rb +4 -2
- data/lib/active_record/associations/collection_association.rb +8 -8
- data/lib/active_record/associations/collection_proxy.rb +2 -4
- data/lib/active_record/associations/has_many_association.rb +2 -2
- data/lib/active_record/associations/has_one_association.rb +3 -1
- data/lib/active_record/associations/join_dependency/join_association.rb +2 -0
- data/lib/active_record/associations/join_dependency/join_part.rb +14 -1
- data/lib/active_record/associations/preloader.rb +3 -2
- data/lib/active_record/attribute_methods.rb +26 -2
- data/lib/active_record/attribute_methods/read.rb +15 -9
- data/lib/active_record/attribute_methods/time_zone_conversion.rb +1 -1
- data/lib/active_record/attribute_methods/write.rb +2 -0
- data/lib/active_record/autosave_association.rb +8 -8
- data/lib/active_record/callbacks.rb +4 -1
- data/lib/active_record/connection_adapters/abstract/database_statements.rb +7 -7
- data/lib/active_record/connection_adapters/abstract/schema_statements.rb +12 -3
- data/lib/active_record/connection_adapters/abstract_adapter.rb +16 -2
- data/lib/active_record/connection_adapters/abstract_mysql_adapter.rb +3 -1
- data/lib/active_record/connection_adapters/column.rb +12 -11
- data/lib/active_record/connection_adapters/mysql2_adapter.rb +9 -3
- data/lib/active_record/connection_adapters/mysql_adapter.rb +19 -9
- data/lib/active_record/connection_adapters/postgresql/cast.rb +1 -1
- data/lib/active_record/connection_adapters/postgresql/database_statements.rb +7 -6
- data/lib/active_record/connection_adapters/postgresql/oid.rb +5 -0
- data/lib/active_record/connection_adapters/postgresql/quoting.rb +2 -0
- data/lib/active_record/connection_adapters/postgresql/schema_statements.rb +7 -10
- data/lib/active_record/connection_adapters/postgresql_adapter.rb +19 -13
- data/lib/active_record/connection_adapters/sqlite3_adapter.rb +8 -5
- data/lib/active_record/core.rb +18 -18
- data/lib/active_record/dynamic_matchers.rb +1 -1
- data/lib/active_record/fixtures.rb +2 -2
- data/lib/active_record/locking/optimistic.rb +1 -1
- data/lib/active_record/migration.rb +1 -1
- data/lib/active_record/migration/command_recorder.rb +4 -1
- data/lib/active_record/model_schema.rb +27 -17
- data/lib/active_record/null_relation.rb +1 -5
- data/lib/active_record/persistence.rb +16 -5
- data/lib/active_record/railtie.rb +1 -0
- data/lib/active_record/railties/databases.rake +4 -1
- data/lib/active_record/reflection.rb +1 -1
- data/lib/active_record/relation.rb +1 -1
- data/lib/active_record/relation/batches.rb +2 -2
- data/lib/active_record/relation/calculations.rb +1 -0
- data/lib/active_record/relation/finder_methods.rb +10 -10
- data/lib/active_record/relation/merger.rb +31 -28
- data/lib/active_record/relation/query_methods.rb +13 -11
- data/lib/active_record/result.rb +15 -1
- data/lib/active_record/sanitization.rb +13 -3
- data/lib/active_record/schema_dumper.rb +5 -1
- data/lib/active_record/tasks/database_tasks.rb +2 -1
- data/lib/active_record/tasks/sqlite_database_tasks.rb +1 -1
- data/lib/active_record/transactions.rb +5 -5
- data/lib/active_record/validations/uniqueness.rb +2 -2
- data/lib/active_record/version.rb +1 -1
- metadata +10 -9
data/lib/active_record/result.rb
CHANGED
@@ -59,7 +59,21 @@ module ActiveRecord
|
|
59
59
|
# used as keys in ActiveRecord::Base's @attributes hash
|
60
60
|
columns = @columns.map { |c| c.dup.freeze }
|
61
61
|
@rows.map { |row|
|
62
|
-
Hash[columns.zip(row)]
|
62
|
+
# In the past we used Hash[columns.zip(row)]
|
63
|
+
# though elegant, the verbose way is much more efficient
|
64
|
+
# both time and memory wise cause it avoids a big array allocation
|
65
|
+
# this method is called a lot and needs to be micro optimised
|
66
|
+
hash = {}
|
67
|
+
|
68
|
+
index = 0
|
69
|
+
length = columns.length
|
70
|
+
|
71
|
+
while index < length
|
72
|
+
hash[columns[index]] = row[index]
|
73
|
+
index += 1
|
74
|
+
end
|
75
|
+
|
76
|
+
hash
|
63
77
|
}
|
64
78
|
end
|
65
79
|
end
|
@@ -89,7 +89,7 @@ module ActiveRecord
|
|
89
89
|
attrs = expand_hash_conditions_for_aggregates(attrs)
|
90
90
|
|
91
91
|
table = Arel::Table.new(table_name, arel_engine).alias(default_table_name)
|
92
|
-
PredicateBuilder.build_from_hash(self
|
92
|
+
PredicateBuilder.build_from_hash(self, attrs, table).map { |b|
|
93
93
|
connection.visitor.accept b
|
94
94
|
}.join(' AND ')
|
95
95
|
end
|
@@ -126,7 +126,17 @@ module ActiveRecord
|
|
126
126
|
raise_if_bind_arity_mismatch(statement, statement.count('?'), values.size)
|
127
127
|
bound = values.dup
|
128
128
|
c = connection
|
129
|
-
statement.gsub('?')
|
129
|
+
statement.gsub('?') do
|
130
|
+
replace_bind_variable(bound.shift, c)
|
131
|
+
end
|
132
|
+
end
|
133
|
+
|
134
|
+
def replace_bind_variable(value, c = connection) #:nodoc:
|
135
|
+
if ActiveRecord::Relation === value
|
136
|
+
value.to_sql
|
137
|
+
else
|
138
|
+
quote_bound_value(value, c)
|
139
|
+
end
|
130
140
|
end
|
131
141
|
|
132
142
|
def replace_named_bind_variables(statement, bind_vars) #:nodoc:
|
@@ -134,7 +144,7 @@ module ActiveRecord
|
|
134
144
|
if $1 == ':' # skip postgresql casts
|
135
145
|
$& # return the whole match
|
136
146
|
elsif bind_vars.include?(match = $2.to_sym)
|
137
|
-
|
147
|
+
replace_bind_variable(bind_vars[match])
|
138
148
|
else
|
139
149
|
raise PreparedStatementInvalid, "missing value for :#{match} in #{statement}"
|
140
150
|
end
|
@@ -106,9 +106,13 @@ HEADER
|
|
106
106
|
end
|
107
107
|
|
108
108
|
tbl.print " create_table #{remove_prefix_and_suffix(table).inspect}"
|
109
|
-
|
109
|
+
pkcol = columns.detect { |c| c.name == pk }
|
110
|
+
if pkcol
|
110
111
|
if pk != 'id'
|
111
112
|
tbl.print %Q(, primary_key: "#{pk}")
|
113
|
+
elsif pkcol.sql_type == 'uuid'
|
114
|
+
tbl.print ", id: :uuid"
|
115
|
+
tbl.print %Q(, default: "#{pkcol.default_function}") if pkcol.default_function
|
112
116
|
end
|
113
117
|
else
|
114
118
|
tbl.print ", id: false"
|
@@ -23,6 +23,7 @@ module ActiveRecord
|
|
23
23
|
# * +fixtures_path+: a path to fixtures directory.
|
24
24
|
# * +migrations_paths+: a list of paths to directories with migrations.
|
25
25
|
# * +seed_loader+: an object which will load seeds, it needs to respond to the +load_seed+ method.
|
26
|
+
# * +root+: a path to the root of the application.
|
26
27
|
#
|
27
28
|
# Example usage of +DatabaseTasks+ outside Rails could look as such:
|
28
29
|
#
|
@@ -37,7 +38,7 @@ module ActiveRecord
|
|
37
38
|
|
38
39
|
attr_writer :current_config
|
39
40
|
attr_accessor :database_configuration, :migrations_paths, :seed_loader, :db_dir,
|
40
|
-
:fixtures_path, :env
|
41
|
+
:fixtures_path, :env, :root
|
41
42
|
|
42
43
|
LOCAL_HOSTS = ['127.0.0.1', 'localhost']
|
43
44
|
|
@@ -3,7 +3,7 @@ module ActiveRecord
|
|
3
3
|
class SQLiteDatabaseTasks # :nodoc:
|
4
4
|
delegate :connection, :establish_connection, to: ActiveRecord::Base
|
5
5
|
|
6
|
-
def initialize(configuration, root =
|
6
|
+
def initialize(configuration, root = ActiveRecord::Tasks::DatabaseTasks.root)
|
7
7
|
@configuration, @root = configuration, root
|
8
8
|
end
|
9
9
|
|
@@ -243,7 +243,7 @@ module ActiveRecord
|
|
243
243
|
if options.is_a?(Hash) && options[:on]
|
244
244
|
assert_valid_transaction_action(options[:on])
|
245
245
|
options[:if] = Array(options[:if])
|
246
|
-
fire_on = Array(options[:on])
|
246
|
+
fire_on = Array(options[:on])
|
247
247
|
options[:if] << "transaction_include_any_action?(#{fire_on})"
|
248
248
|
end
|
249
249
|
end
|
@@ -286,17 +286,17 @@ module ActiveRecord
|
|
286
286
|
clear_transaction_record_state
|
287
287
|
end
|
288
288
|
|
289
|
-
# Call the after_commit callbacks
|
289
|
+
# Call the +after_commit+ callbacks.
|
290
290
|
#
|
291
291
|
# Ensure that it is not called if the object was never persisted (failed create),
|
292
|
-
# but call it after the commit of a destroyed object
|
292
|
+
# but call it after the commit of a destroyed object.
|
293
293
|
def committed! #:nodoc:
|
294
294
|
run_callbacks :commit if destroyed? || persisted?
|
295
295
|
ensure
|
296
296
|
clear_transaction_record_state
|
297
297
|
end
|
298
298
|
|
299
|
-
# Call the
|
299
|
+
# Call the +after_rollback+ callbacks. The +force_restore_state+ argument indicates if the record
|
300
300
|
# state should be rolled back to the beginning or just to the last savepoint.
|
301
301
|
def rolledback!(force_restore_state = false) #:nodoc:
|
302
302
|
run_callbacks :rollback
|
@@ -304,7 +304,7 @@ module ActiveRecord
|
|
304
304
|
restore_transaction_record_state(force_restore_state)
|
305
305
|
end
|
306
306
|
|
307
|
-
# Add the record to the current transaction so that the
|
307
|
+
# Add the record to the current transaction so that the +after_rollback+ and +after_commit+ callbacks
|
308
308
|
# can be called.
|
309
309
|
def add_to_transaction
|
310
310
|
if self.class.connection.add_transaction_record(self)
|
@@ -202,8 +202,8 @@ module ActiveRecord
|
|
202
202
|
# will result in the default Rails exception page being shown), or you
|
203
203
|
# can catch it and restart the transaction (e.g. by telling the user
|
204
204
|
# that the title already exists, and asking him to re-enter the title).
|
205
|
-
# This technique is also known as
|
206
|
-
# http://en.wikipedia.org/wiki/Optimistic_concurrency_control.
|
205
|
+
# This technique is also known as
|
206
|
+
# {optimistic concurrency control}[http://en.wikipedia.org/wiki/Optimistic_concurrency_control].
|
207
207
|
#
|
208
208
|
# The bundled ActiveRecord::ConnectionAdapters distinguish unique index
|
209
209
|
# constraint errors from other types of database errors by throwing an
|
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: 4.0.
|
4
|
+
version: 4.0.1.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: 2013-
|
11
|
+
date: 2013-10-17 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: 4.0.
|
19
|
+
version: 4.0.1.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: 4.0.
|
26
|
+
version: 4.0.1.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: 4.0.
|
33
|
+
version: 4.0.1.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: 4.0.
|
40
|
+
version: 4.0.1.rc1
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: arel
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -81,6 +81,7 @@ files:
|
|
81
81
|
- examples/performance.rb
|
82
82
|
- examples/simple.rb
|
83
83
|
- lib/active_record/aggregations.rb
|
84
|
+
- lib/active_record/association_relation.rb
|
84
85
|
- lib/active_record/associations/alias_tracker.rb
|
85
86
|
- lib/active_record/associations/association.rb
|
86
87
|
- lib/active_record/associations/association_scope.rb
|
@@ -254,12 +255,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
254
255
|
version: 1.9.3
|
255
256
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
256
257
|
requirements:
|
257
|
-
- - '
|
258
|
+
- - '>'
|
258
259
|
- !ruby/object:Gem::Version
|
259
|
-
version:
|
260
|
+
version: 1.3.1
|
260
261
|
requirements: []
|
261
262
|
rubyforge_project:
|
262
|
-
rubygems_version: 2.0.
|
263
|
+
rubygems_version: 2.0.6
|
263
264
|
signing_key:
|
264
265
|
specification_version: 4
|
265
266
|
summary: Object-relational mapper framework (part of Rails).
|