activerecord 4.2.0.beta4 → 4.2.0.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 +107 -34
- data/lib/active_record/aggregations.rb +2 -2
- data/lib/active_record/associations.rb +1 -1
- data/lib/active_record/associations/alias_tracker.rb +3 -12
- data/lib/active_record/associations/association_scope.rb +1 -2
- data/lib/active_record/associations/builder/has_and_belongs_to_many.rb +2 -2
- data/lib/active_record/associations/collection_association.rb +29 -6
- data/lib/active_record/associations/has_many_association.rb +1 -1
- data/lib/active_record/associations/has_many_through_association.rb +2 -2
- data/lib/active_record/associations/join_dependency.rb +1 -1
- data/lib/active_record/associations/join_dependency/join_association.rb +1 -1
- data/lib/active_record/associations/preloader.rb +1 -0
- data/lib/active_record/associations/preloader/association.rb +3 -8
- data/lib/active_record/associations/preloader/through_association.rb +1 -0
- data/lib/active_record/associations/singular_association.rb +2 -1
- data/lib/active_record/attribute_methods.rb +2 -2
- data/lib/active_record/attribute_methods/dirty.rb +1 -1
- data/lib/active_record/attribute_methods/primary_key.rb +2 -1
- data/lib/active_record/attribute_methods/read.rb +13 -5
- data/lib/active_record/attribute_methods/time_zone_conversion.rb +1 -1
- data/lib/active_record/attribute_set.rb +7 -11
- data/lib/active_record/attribute_set/builder.rb +66 -17
- data/lib/active_record/attributes.rb +20 -3
- data/lib/active_record/connection_adapters/abstract/database_statements.rb +0 -4
- data/lib/active_record/connection_adapters/abstract/schema_creation.rb +1 -3
- data/lib/active_record/connection_adapters/abstract/schema_definitions.rb +25 -24
- data/lib/active_record/connection_adapters/abstract/schema_statements.rb +9 -3
- data/lib/active_record/connection_adapters/abstract_adapter.rb +9 -7
- data/lib/active_record/connection_adapters/abstract_mysql_adapter.rb +25 -13
- data/lib/active_record/connection_adapters/connection_specification.rb +1 -1
- data/lib/active_record/connection_adapters/mysql2_adapter.rb +6 -0
- data/lib/active_record/connection_adapters/mysql_adapter.rb +6 -2
- data/lib/active_record/connection_adapters/postgresql/database_statements.rb +0 -4
- data/lib/active_record/connection_adapters/postgresql/quoting.rb +6 -16
- data/lib/active_record/connection_adapters/postgresql/schema_statements.rb +29 -7
- data/lib/active_record/connection_adapters/postgresql/utils.rb +15 -4
- data/lib/active_record/connection_adapters/postgresql_adapter.rb +15 -6
- data/lib/active_record/connection_adapters/sqlite3_adapter.rb +5 -7
- data/lib/active_record/connection_handling.rb +1 -1
- data/lib/active_record/core.rb +5 -3
- data/lib/active_record/enum.rb +1 -1
- data/lib/active_record/errors.rb +21 -0
- data/lib/active_record/fixtures.rb +4 -2
- data/lib/active_record/gem_version.rb +1 -1
- data/lib/active_record/locking/optimistic.rb +1 -1
- data/lib/active_record/migration.rb +15 -4
- data/lib/active_record/model_schema.rb +8 -4
- data/lib/active_record/persistence.rb +5 -5
- data/lib/active_record/railtie.rb +0 -2
- data/lib/active_record/railties/databases.rake +7 -6
- data/lib/active_record/reflection.rb +2 -2
- data/lib/active_record/relation.rb +21 -13
- data/lib/active_record/relation/calculations.rb +1 -0
- data/lib/active_record/relation/finder_methods.rb +8 -5
- data/lib/active_record/relation/merger.rb +0 -12
- data/lib/active_record/relation/predicate_builder/relation_handler.rb +1 -1
- data/lib/active_record/relation/query_methods.rb +30 -18
- data/lib/active_record/sanitization.rb +4 -1
- data/lib/active_record/schema_dumper.rb +1 -6
- data/lib/active_record/scoping/named.rb +1 -1
- data/lib/active_record/statement_cache.rb +21 -10
- data/lib/active_record/tasks/database_tasks.rb +17 -2
- data/lib/active_record/tasks/mysql_database_tasks.rb +1 -0
- data/lib/active_record/type.rb +1 -0
- data/lib/active_record/type/big_integer.rb +13 -0
- data/lib/active_record/type/decimal_without_scale.rb +2 -2
- data/lib/active_record/type/hash_lookup_type_map.rb +5 -7
- data/lib/active_record/type/integer.rb +29 -1
- data/lib/active_record/type/serialized.rb +1 -1
- data/lib/active_record/type/string.rb +4 -4
- data/lib/active_record/type/type_map.rb +23 -7
- data/lib/active_record/validations.rb +4 -3
- data/lib/active_record/validations/uniqueness.rb +1 -1
- data/lib/rails/generators/active_record/migration/templates/create_table_migration.rb +3 -0
- data/lib/rails/generators/active_record/migration/templates/migration.rb +6 -0
- metadata +15 -20
@@ -15,8 +15,8 @@ module ActiveRecord
|
|
15
15
|
case value
|
16
16
|
when ::Numeric, ActiveSupport::Duration then value.to_s
|
17
17
|
when ::String then ::String.new(value)
|
18
|
-
when true then "
|
19
|
-
when false then "
|
18
|
+
when true then "t"
|
19
|
+
when false then "f"
|
20
20
|
else super
|
21
21
|
end
|
22
22
|
end
|
@@ -25,8 +25,8 @@ module ActiveRecord
|
|
25
25
|
|
26
26
|
def cast_value(value)
|
27
27
|
case value
|
28
|
-
when true then "
|
29
|
-
when false then "
|
28
|
+
when true then "t"
|
29
|
+
when false then "f"
|
30
30
|
# String.new is slightly faster than dup
|
31
31
|
else ::String.new(value.to_s)
|
32
32
|
end
|
@@ -1,24 +1,28 @@
|
|
1
|
+
require 'thread_safe'
|
2
|
+
|
1
3
|
module ActiveRecord
|
2
4
|
module Type
|
3
5
|
class TypeMap # :nodoc:
|
4
6
|
def initialize
|
5
7
|
@mapping = {}
|
8
|
+
@cache = ThreadSafe::Cache.new do |h, key|
|
9
|
+
h.fetch_or_store(key, ThreadSafe::Cache.new)
|
10
|
+
end
|
6
11
|
end
|
7
12
|
|
8
13
|
def lookup(lookup_key, *args)
|
9
|
-
|
10
|
-
|
11
|
-
end
|
14
|
+
fetch(lookup_key, *args) { default_value }
|
15
|
+
end
|
12
16
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
default_value
|
17
|
+
def fetch(lookup_key, *args, &block)
|
18
|
+
@cache[lookup_key].fetch_or_store(args) do
|
19
|
+
perform_fetch(lookup_key, *args, &block)
|
17
20
|
end
|
18
21
|
end
|
19
22
|
|
20
23
|
def register_type(key, value = nil, &block)
|
21
24
|
raise ::ArgumentError unless value || block
|
25
|
+
@cache.clear
|
22
26
|
|
23
27
|
if block
|
24
28
|
@mapping[key] = block
|
@@ -40,6 +44,18 @@ module ActiveRecord
|
|
40
44
|
|
41
45
|
private
|
42
46
|
|
47
|
+
def perform_fetch(lookup_key, *args)
|
48
|
+
matching_pair = @mapping.reverse_each.detect do |key, _|
|
49
|
+
key === lookup_key
|
50
|
+
end
|
51
|
+
|
52
|
+
if matching_pair
|
53
|
+
matching_pair.last.call(lookup_key, *args)
|
54
|
+
else
|
55
|
+
yield lookup_key, *args
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
43
59
|
def default_value
|
44
60
|
@default_value ||= Value.new
|
45
61
|
end
|
@@ -5,13 +5,14 @@ module ActiveRecord
|
|
5
5
|
# +record+ method to retrieve the record which did not validate.
|
6
6
|
#
|
7
7
|
# begin
|
8
|
-
#
|
8
|
+
# complex_operation_that_internally_calls_save!
|
9
9
|
# rescue ActiveRecord::RecordInvalid => invalid
|
10
10
|
# puts invalid.record.errors
|
11
11
|
# end
|
12
12
|
class RecordInvalid < ActiveRecordError
|
13
|
-
attr_reader :record
|
14
|
-
|
13
|
+
attr_reader :record
|
14
|
+
|
15
|
+
def initialize(record)
|
15
16
|
@record = record
|
16
17
|
errors = @record.errors.full_messages.join(", ")
|
17
18
|
super(I18n.t(:"#{@record.class.i18n_scope}.errors.messages.record_invalid", :errors => errors, :default => :"errors.messages.record_invalid"))
|
@@ -79,7 +79,7 @@ module ActiveRecord
|
|
79
79
|
scope_value = record.send(reflection.foreign_key)
|
80
80
|
scope_item = reflection.foreign_key
|
81
81
|
else
|
82
|
-
scope_value = record.
|
82
|
+
scope_value = record._read_attribute(scope_item)
|
83
83
|
end
|
84
84
|
relation = relation.and(table[scope_item].eq(scope_value))
|
85
85
|
end
|
@@ -14,6 +14,9 @@ class <%= migration_class_name %> < ActiveRecord::Migration
|
|
14
14
|
end
|
15
15
|
<% attributes_with_index.each do |attribute| -%>
|
16
16
|
add_index :<%= table_name %>, :<%= attribute.index_name %><%= attribute.inject_index_options %>
|
17
|
+
<% end -%>
|
18
|
+
<% attributes.select(&:reference?).reject(&:polymorphic?).each do |attribute| -%>
|
19
|
+
add_foreign_key :<%= table_name %>, :<%= attribute.name.pluralize %>
|
17
20
|
<% end -%>
|
18
21
|
end
|
19
22
|
end
|
@@ -4,6 +4,9 @@ class <%= migration_class_name %> < ActiveRecord::Migration
|
|
4
4
|
<% attributes.each do |attribute| -%>
|
5
5
|
<%- if attribute.reference? -%>
|
6
6
|
add_reference :<%= table_name %>, :<%= attribute.name %><%= attribute.inject_options %>
|
7
|
+
<%- unless attribute.polymorphic? -%>
|
8
|
+
add_foreign_key :<%= table_name %>, :<%= attribute.name.pluralize %>
|
9
|
+
<%- end -%>
|
7
10
|
<%- else -%>
|
8
11
|
add_column :<%= table_name %>, :<%= attribute.name %>, :<%= attribute.type %><%= attribute.inject_options %>
|
9
12
|
<%- if attribute.has_index? -%>
|
@@ -26,6 +29,9 @@ class <%= migration_class_name %> < ActiveRecord::Migration
|
|
26
29
|
<%- if migration_action -%>
|
27
30
|
<%- if attribute.reference? -%>
|
28
31
|
remove_reference :<%= table_name %>, :<%= attribute.name %><%= attribute.inject_options %>
|
32
|
+
<%- unless attribute.polymorphic? -%>
|
33
|
+
remove_foreign_key :<%= table_name %>, :<%= attribute.name.pluralize %>
|
34
|
+
<%- end -%>
|
29
35
|
<%- else -%>
|
30
36
|
<%- if attribute.has_index? -%>
|
31
37
|
remove_index :<%= table_name %>, :<%= attribute.index_name %><%= attribute.inject_index_options %>
|
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.2.0.
|
4
|
+
version: 4.2.0.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: 2014-
|
11
|
+
date: 2014-11-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -16,48 +16,42 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - '='
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 4.2.0.
|
19
|
+
version: 4.2.0.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.2.0.
|
26
|
+
version: 4.2.0.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.2.0.
|
33
|
+
version: 4.2.0.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.2.0.
|
40
|
+
version: 4.2.0.rc1
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: arel
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- -
|
45
|
+
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: 6.0
|
48
|
-
- - <
|
49
|
-
- !ruby/object:Gem::Version
|
50
|
-
version: '6.1'
|
47
|
+
version: '6.0'
|
51
48
|
type: :runtime
|
52
49
|
prerelease: false
|
53
50
|
version_requirements: !ruby/object:Gem::Requirement
|
54
51
|
requirements:
|
55
|
-
- -
|
56
|
-
- !ruby/object:Gem::Version
|
57
|
-
version: 6.0.0.beta2
|
58
|
-
- - <
|
52
|
+
- - "~>"
|
59
53
|
- !ruby/object:Gem::Version
|
60
|
-
version: '6.
|
54
|
+
version: '6.0'
|
61
55
|
description: Databases on Rails. Build a persistent domain model by mapping database
|
62
56
|
tables to Ruby classes. Strong conventions for associations, validations, aggregations,
|
63
57
|
migrations, and testing come baked-in.
|
@@ -252,6 +246,7 @@ files:
|
|
252
246
|
- lib/active_record/transactions.rb
|
253
247
|
- lib/active_record/translation.rb
|
254
248
|
- lib/active_record/type.rb
|
249
|
+
- lib/active_record/type/big_integer.rb
|
255
250
|
- lib/active_record/type/binary.rb
|
256
251
|
- lib/active_record/type/boolean.rb
|
257
252
|
- lib/active_record/type/date.rb
|
@@ -290,23 +285,23 @@ licenses:
|
|
290
285
|
metadata: {}
|
291
286
|
post_install_message:
|
292
287
|
rdoc_options:
|
293
|
-
- --main
|
288
|
+
- "--main"
|
294
289
|
- README.rdoc
|
295
290
|
require_paths:
|
296
291
|
- lib
|
297
292
|
required_ruby_version: !ruby/object:Gem::Requirement
|
298
293
|
requirements:
|
299
|
-
- -
|
294
|
+
- - ">="
|
300
295
|
- !ruby/object:Gem::Version
|
301
296
|
version: 1.9.3
|
302
297
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
303
298
|
requirements:
|
304
|
-
- -
|
299
|
+
- - ">"
|
305
300
|
- !ruby/object:Gem::Version
|
306
301
|
version: 1.3.1
|
307
302
|
requirements: []
|
308
303
|
rubyforge_project:
|
309
|
-
rubygems_version: 2.2.
|
304
|
+
rubygems_version: 2.2.2
|
310
305
|
signing_key:
|
311
306
|
specification_version: 4
|
312
307
|
summary: Object-relational mapper framework (part of Rails).
|