activerecord 4.1.9 → 4.1.10.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 +43 -0
- data/lib/active_record/associations/collection_association.rb +10 -0
- data/lib/active_record/associations/collection_proxy.rb +4 -0
- data/lib/active_record/associations/through_association.rb +11 -0
- data/lib/active_record/connection_adapters/abstract/connection_pool.rb +1 -1
- data/lib/active_record/connection_adapters/abstract_adapter.rb +6 -1
- data/lib/active_record/gem_version.rb +2 -2
- data/lib/active_record/persistence.rb +2 -1
- data/lib/active_record/reflection.rb +1 -1
- data/lib/active_record/relation/batches.rb +1 -0
- data/lib/active_record/relation/predicate_builder.rb +23 -5
- data/lib/active_record/relation/predicate_builder/relation_handler.rb +4 -0
- data/lib/active_record/relation/query_methods.rb +17 -11
- data/lib/active_record/validations/uniqueness.rb +7 -1
- metadata +8 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e329025c048dbd366e2fca4091303d14803fef0f
|
4
|
+
data.tar.gz: 2fb5d5bdb86e35ee822fe7bd36923913dfc22dc9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 59ceda382ce5783d72da28327e6981431f7251db2b947a3421182850f345503e751698847a2b09f45a228cac3dff48f9cd4110a673e752defc00866ee9ad05a6
|
7
|
+
data.tar.gz: 844e1f73eda741d030d66af1f56abdc261effa32bf86e2173034381e85c6131230204a78246d15f2eed7dba7c7d2e0c50f451608a87443b1a85d7b6350a8739e
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,46 @@
|
|
1
|
+
* Fixed ActiveRecord::Relation#becomes! and changed_attributes issues for type column
|
2
|
+
|
3
|
+
Fixes #17139.
|
4
|
+
|
5
|
+
*Miklos Fazekas*
|
6
|
+
|
7
|
+
* A `NullRelation` should represent nothing. This fixes a bug where
|
8
|
+
`Comment.where(post_id: Post.none)` returned a non-empty result.
|
9
|
+
|
10
|
+
Closes #15176.
|
11
|
+
|
12
|
+
*Matthew Draper*, *Yves Senn*
|
13
|
+
|
14
|
+
* Respect custom primary keys for associations when calling `Relation#where`
|
15
|
+
|
16
|
+
Fixes #18813.
|
17
|
+
|
18
|
+
*Sean Griffin*
|
19
|
+
|
20
|
+
* Fixed ActiveRecord::Relation#group method when argument is SQL reserved key word:
|
21
|
+
|
22
|
+
SplitTest.group(:key).count
|
23
|
+
Property.group(:value).count
|
24
|
+
|
25
|
+
*Bogdan Gusiev*
|
26
|
+
|
27
|
+
* Fixed setting of foreign_key for through associations while building of new record.
|
28
|
+
|
29
|
+
Fixes #12698.
|
30
|
+
|
31
|
+
*Ivan Antropov*
|
32
|
+
|
33
|
+
* Fixed automatic inverse_of for models nested in module.
|
34
|
+
|
35
|
+
*Andrew McCloud*
|
36
|
+
|
37
|
+
* Fix `reaping_frequency` option when the value is a string.
|
38
|
+
|
39
|
+
This usually happens when it is configured using `DATABASE_URL`.
|
40
|
+
|
41
|
+
*korbin*
|
42
|
+
|
43
|
+
|
1
44
|
## Rails 4.1.9 (January 6, 2015) ##
|
2
45
|
|
3
46
|
* `db:schema:load` and `db:structure:load` no longer purge the database
|
@@ -129,6 +129,16 @@ module ActiveRecord
|
|
129
129
|
first_nth_or_last(:last, *args)
|
130
130
|
end
|
131
131
|
|
132
|
+
def take
|
133
|
+
if loaded?
|
134
|
+
target.first
|
135
|
+
else
|
136
|
+
scope.take.tap do |record|
|
137
|
+
set_inverse_instance record if record.is_a? ActiveRecord::Base
|
138
|
+
end
|
139
|
+
end
|
140
|
+
end
|
141
|
+
|
132
142
|
def build(attributes = {}, &block)
|
133
143
|
if attributes.is_a?(Array)
|
134
144
|
attributes.collect { |attr| build(attr, &block) }
|
@@ -226,6 +226,10 @@ module ActiveRecord
|
|
226
226
|
@association.last(*args)
|
227
227
|
end
|
228
228
|
|
229
|
+
def take
|
230
|
+
@association.take
|
231
|
+
end
|
232
|
+
|
229
233
|
# Returns a new object of the collection type that has been instantiated
|
230
234
|
# with +attributes+ and linked to this object, but have not yet been saved.
|
231
235
|
# You can pass an array of attributes hashes, this will return an array
|
@@ -92,6 +92,17 @@ module ActiveRecord
|
|
92
92
|
raise HasManyThroughNestedAssociationsAreReadonly.new(owner, reflection)
|
93
93
|
end
|
94
94
|
end
|
95
|
+
|
96
|
+
def build_record(attributes)
|
97
|
+
inverse = source_reflection.inverse_of
|
98
|
+
target = through_association.target
|
99
|
+
|
100
|
+
if inverse && target && !target.is_a?(Array)
|
101
|
+
attributes[inverse.foreign_key] = target.id
|
102
|
+
end
|
103
|
+
|
104
|
+
super(attributes)
|
105
|
+
end
|
95
106
|
end
|
96
107
|
end
|
97
108
|
end
|
@@ -238,7 +238,7 @@ module ActiveRecord
|
|
238
238
|
|
239
239
|
@checkout_timeout = (spec.config[:checkout_timeout] && spec.config[:checkout_timeout].to_f) || 5
|
240
240
|
@dead_connection_timeout = (spec.config[:dead_connection_timeout] && spec.config[:dead_connection_timeout].to_f) || 5
|
241
|
-
@reaper
|
241
|
+
@reaper = Reaper.new(self, (spec.config[:reaping_frequency] && spec.config[:reaping_frequency].to_f))
|
242
242
|
@reaper.run
|
243
243
|
|
244
244
|
# default max pool size to 5
|
@@ -356,7 +356,12 @@ module ActiveRecord
|
|
356
356
|
protected
|
357
357
|
|
358
358
|
def translate_exception_class(e, sql)
|
359
|
-
|
359
|
+
begin
|
360
|
+
message = "#{e.class.name}: #{e.message}: #{sql}"
|
361
|
+
rescue Encoding::CompatibilityError
|
362
|
+
message = "#{e.class.name}: #{e.message.force_encoding sql.encoding}: #{sql}"
|
363
|
+
end
|
364
|
+
|
360
365
|
@logger.error message if @logger
|
361
366
|
exception = translate_exception(e, message)
|
362
367
|
exception.set_backtrace e.backtrace
|
@@ -181,7 +181,8 @@ module ActiveRecord
|
|
181
181
|
became = klass.new
|
182
182
|
became.instance_variable_set("@attributes", @attributes)
|
183
183
|
became.instance_variable_set("@attributes_cache", @attributes_cache)
|
184
|
-
|
184
|
+
changed_attributes = @changed_attributes if defined?(@changed_attributes)
|
185
|
+
became.instance_variable_set("@changed_attributes", changed_attributes || {})
|
185
186
|
became.instance_variable_set("@new_record", new_record?)
|
186
187
|
became.instance_variable_set("@destroyed", destroyed?)
|
187
188
|
became.instance_variable_set("@errors", errors)
|
@@ -432,7 +432,7 @@ module ActiveRecord
|
|
432
432
|
# returns either nil or the inverse association name that it finds.
|
433
433
|
def automatic_inverse_of
|
434
434
|
if can_find_inverse_of_automatically?(self)
|
435
|
-
inverse_name = ActiveSupport::Inflector.underscore(options[:as] || active_record.name).to_sym
|
435
|
+
inverse_name = ActiveSupport::Inflector.underscore(options[:as] || active_record.name.demodulize).to_sym
|
436
436
|
|
437
437
|
begin
|
438
438
|
reflection = klass._reflect_on_association(inverse_name)
|
@@ -61,6 +61,8 @@ module ActiveRecord
|
|
61
61
|
end
|
62
62
|
|
63
63
|
column = reflection.foreign_key
|
64
|
+
primary_key = reflection.association_primary_key(base_class)
|
65
|
+
value = convert_value_to_association_ids(value, primary_key)
|
64
66
|
end
|
65
67
|
|
66
68
|
queries << build(table[column], value)
|
@@ -114,12 +116,28 @@ module ActiveRecord
|
|
114
116
|
register_handler(Array, ArrayHandler.new)
|
115
117
|
|
116
118
|
private
|
117
|
-
def self.build(attribute, value)
|
118
|
-
handler_for(value).call(attribute, value)
|
119
|
-
end
|
120
119
|
|
121
|
-
|
122
|
-
|
120
|
+
def self.build(attribute, value)
|
121
|
+
handler_for(value).call(attribute, value)
|
122
|
+
end
|
123
|
+
private_class_method :build
|
124
|
+
|
125
|
+
def self.handler_for(object)
|
126
|
+
@handlers.detect { |klass, _| klass === object }.last
|
127
|
+
end
|
128
|
+
private_class_method :handler_for
|
129
|
+
|
130
|
+
def self.convert_value_to_association_ids(value, primary_key)
|
131
|
+
case value
|
132
|
+
when Relation
|
133
|
+
value.select(primary_key)
|
134
|
+
when Array
|
135
|
+
value.map { |v| convert_value_to_association_ids(v, primary_key) }
|
136
|
+
when Base
|
137
|
+
value.read_attribute(primary_key)
|
138
|
+
else
|
139
|
+
value
|
123
140
|
end
|
141
|
+
end
|
124
142
|
end
|
125
143
|
end
|
@@ -677,11 +677,11 @@ module ActiveRecord
|
|
677
677
|
# end
|
678
678
|
#
|
679
679
|
def none
|
680
|
-
extending(NullRelation)
|
680
|
+
where("1=0").extending!(NullRelation)
|
681
681
|
end
|
682
682
|
|
683
683
|
def none! # :nodoc:
|
684
|
-
extending!(NullRelation)
|
684
|
+
where!("1=0").extending!(NullRelation)
|
685
685
|
end
|
686
686
|
|
687
687
|
# Sets readonly attributes for the returned relation. If value is
|
@@ -855,12 +855,11 @@ module ActiveRecord
|
|
855
855
|
|
856
856
|
arel.take(connection.sanitize_limit(limit_value)) if limit_value
|
857
857
|
arel.skip(offset_value.to_i) if offset_value
|
858
|
-
|
859
|
-
arel.group(*group_values.uniq.reject(&:blank?)) unless group_values.empty?
|
858
|
+
arel.group(*arel_columns(group_values.uniq.reject(&:blank?))) unless group_values.empty?
|
860
859
|
|
861
860
|
build_order(arel)
|
862
861
|
|
863
|
-
build_select(arel
|
862
|
+
build_select(arel)
|
864
863
|
|
865
864
|
arel.distinct(distinct_value)
|
866
865
|
arel.from(build_from) if from_value
|
@@ -1008,17 +1007,24 @@ module ActiveRecord
|
|
1008
1007
|
manager
|
1009
1008
|
end
|
1010
1009
|
|
1011
|
-
def build_select(arel
|
1012
|
-
if
|
1013
|
-
|
1014
|
-
columns_hash.key?(field.to_s) ? arel_table[field] : field
|
1015
|
-
end
|
1016
|
-
arel.project(*expanded_select)
|
1010
|
+
def build_select(arel)
|
1011
|
+
if select_values.any?
|
1012
|
+
arel.project(*arel_columns(select_values.uniq))
|
1017
1013
|
else
|
1018
1014
|
arel.project(@klass.arel_table[Arel.star])
|
1019
1015
|
end
|
1020
1016
|
end
|
1021
1017
|
|
1018
|
+
def arel_columns(columns)
|
1019
|
+
columns.map do |field|
|
1020
|
+
if columns_hash.key?(field.to_s)
|
1021
|
+
arel_table[field]
|
1022
|
+
else
|
1023
|
+
field
|
1024
|
+
end
|
1025
|
+
end
|
1026
|
+
end
|
1027
|
+
|
1022
1028
|
def reverse_sql_order(order_query)
|
1023
1029
|
order_query = ["#{quoted_table_name}.#{quoted_primary_key} ASC"] if order_query.empty?
|
1024
1030
|
|
@@ -81,7 +81,13 @@ module ActiveRecord
|
|
81
81
|
else
|
82
82
|
scope_value = record.read_attribute(scope_item)
|
83
83
|
end
|
84
|
-
|
84
|
+
|
85
|
+
# This is basically emulating an Arel::Nodes::Casted
|
86
|
+
column = record.class.columns_hash[scope_item.to_s]
|
87
|
+
quoted_value = record.class.connection.quote(scope_value, column)
|
88
|
+
node = Arel::Nodes::SqlLiteral.new(quoted_value)
|
89
|
+
|
90
|
+
relation = relation.and(table[scope_item].eq(node))
|
85
91
|
end
|
86
92
|
|
87
93
|
relation
|
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.1.
|
4
|
+
version: 4.1.10.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: 2015-
|
11
|
+
date: 2015-02-20 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.1.
|
19
|
+
version: 4.1.10.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.1.
|
26
|
+
version: 4.1.10.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.1.
|
33
|
+
version: 4.1.10.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.1.
|
40
|
+
version: 4.1.10.rc1
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: arel
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -243,9 +243,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
243
243
|
version: 1.9.3
|
244
244
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
245
245
|
requirements:
|
246
|
-
- - "
|
246
|
+
- - ">"
|
247
247
|
- !ruby/object:Gem::Version
|
248
|
-
version:
|
248
|
+
version: 1.3.1
|
249
249
|
requirements: []
|
250
250
|
rubyforge_project:
|
251
251
|
rubygems_version: 2.4.5
|