activerecord 4.1.0.rc1 → 4.1.0.rc2
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 +37 -1
- data/README.rdoc +1 -1
- data/lib/active_record/associations.rb +1 -1
- data/lib/active_record/associations/association.rb +1 -1
- data/lib/active_record/associations/collection_association.rb +3 -7
- data/lib/active_record/associations/has_many_through_association.rb +1 -2
- data/lib/active_record/attribute_methods.rb +2 -1
- data/lib/active_record/autosave_association.rb +1 -1
- data/lib/active_record/connection_adapters/abstract/schema_statements.rb +1 -1
- data/lib/active_record/connection_adapters/connection_specification.rb +2 -2
- data/lib/active_record/connection_handling.rb +5 -9
- data/lib/active_record/gem_version.rb +15 -0
- data/lib/active_record/persistence.rb +3 -1
- data/lib/active_record/relation.rb +10 -1
- data/lib/active_record/relation/query_methods.rb +2 -0
- data/lib/active_record/validations/uniqueness.rb +7 -0
- data/lib/active_record/version.rb +4 -7
- metadata +7 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ea5ed56a85b6c2570bb72ece981880267579ecf4
|
4
|
+
data.tar.gz: d16aec37093f9ea61b393a28f1cc10952aef6003
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5deb7e2666b956da509b5d8178cb28e4147ea7b3f34664df422553cc1d063f09777bb81ab5bceb3624cece5d4a88617f4e3e20394aae22db780fbae66b512071
|
7
|
+
data.tar.gz: af8738dc598c8f482fde1bb4135eead1b955fd9d2b7632aaa17d7600b9b09a38e9df5be1e343616262838c03a00805a33a0f5111e4b51d9d330919c3424e3e56
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,39 @@
|
|
1
|
+
* `where.not` adds `references` for `includes` like normal `where` calls do.
|
2
|
+
|
3
|
+
Fixes #14406.
|
4
|
+
|
5
|
+
*Yves Senn*
|
6
|
+
|
7
|
+
* `includes` is able to detect the right preloading strategy when string
|
8
|
+
joins are involved.
|
9
|
+
|
10
|
+
Fixes #14109.
|
11
|
+
|
12
|
+
*Aaron Patterson*, *Yves Senn*
|
13
|
+
|
14
|
+
* Fixed error with validation with enum fields for records where the
|
15
|
+
value for any enum attribute is always evaluated as 0 during
|
16
|
+
uniqueness validation.
|
17
|
+
|
18
|
+
Fixes #14172.
|
19
|
+
|
20
|
+
*Vilius Luneckas* *Ahmed AbouElhamayed*
|
21
|
+
|
22
|
+
* `before_add` callbacks are fired before the record is saved on
|
23
|
+
`has_and_belongs_to_many` assocations *and* on `has_many :through`
|
24
|
+
associations. Before this change, `before_add` callbacks would be fired
|
25
|
+
before the record was saved on `has_and_belongs_to_many` associations, but
|
26
|
+
*not* on `has_many :through` associations.
|
27
|
+
|
28
|
+
Fixes #14144.
|
29
|
+
|
30
|
+
* Fixed STI classes not defining an attribute method if there is a
|
31
|
+
conflicting private method defined on its ancestors.
|
32
|
+
|
33
|
+
Fixes #11569.
|
34
|
+
|
35
|
+
*Godfrey Chan*
|
36
|
+
|
1
37
|
* Default scopes are no longer overriden by chained conditions.
|
2
38
|
|
3
39
|
Before this change when you defined a `default_scope` in a model
|
@@ -46,7 +82,7 @@
|
|
46
82
|
|
47
83
|
class User < ActiveRecord::Base
|
48
84
|
default_scope { where state: 'pending' }
|
49
|
-
scope :active, -> {
|
85
|
+
scope :active, -> { unscope(where: :state).where(state: 'active') }
|
50
86
|
scope :inactive, -> { rewhere state: 'inactive' }
|
51
87
|
end
|
52
88
|
|
data/README.rdoc
CHANGED
@@ -192,7 +192,7 @@ The latest version of Active Record can be installed with RubyGems:
|
|
192
192
|
|
193
193
|
Source code can be downloaded as part of the Rails project on GitHub:
|
194
194
|
|
195
|
-
* https://github.com/rails/rails/tree/
|
195
|
+
* https://github.com/rails/rails/tree/4-1-stable/activerecord
|
196
196
|
|
197
197
|
|
198
198
|
== License
|
@@ -1584,7 +1584,7 @@ module ActiveRecord
|
|
1584
1584
|
hm_options[:through] = middle_reflection.name
|
1585
1585
|
hm_options[:source] = join_model.right_reflection.name
|
1586
1586
|
|
1587
|
-
[:before_add, :after_add, :before_remove, :after_remove, :autosave].each do |k|
|
1587
|
+
[:before_add, :after_add, :before_remove, :after_remove, :autosave, :validate].each do |k|
|
1588
1588
|
hm_options[k] = options[k] if options.key? k
|
1589
1589
|
end
|
1590
1590
|
|
@@ -232,7 +232,7 @@ module ActiveRecord
|
|
232
232
|
|
233
233
|
# Returns true if record contains the foreign_key
|
234
234
|
def foreign_key_for?(record)
|
235
|
-
record.
|
235
|
+
record.has_attribute?(reflection.foreign_key)
|
236
236
|
end
|
237
237
|
|
238
238
|
# This should be implemented to return the values of the relevant key(s) on the owner,
|
@@ -24,10 +24,6 @@ module ActiveRecord
|
|
24
24
|
# If you need to work on all current children, new and existing records,
|
25
25
|
# +load_target+ and the +loaded+ flag are your friends.
|
26
26
|
class CollectionAssociation < Association #:nodoc:
|
27
|
-
def initialize(owner, reflection)
|
28
|
-
super
|
29
|
-
@proxy = CollectionProxy.create(klass, self)
|
30
|
-
end
|
31
27
|
|
32
28
|
# Implements the reader method, e.g. foo.items for Foo.has_many :items
|
33
29
|
def reader(force_reload = false)
|
@@ -37,7 +33,7 @@ module ActiveRecord
|
|
37
33
|
reload
|
38
34
|
end
|
39
35
|
|
40
|
-
@proxy
|
36
|
+
@proxy ||= CollectionProxy.create(klass, self)
|
41
37
|
end
|
42
38
|
|
43
39
|
# Implements the writer method, e.g. foo.items= for Foo.has_many :items
|
@@ -517,13 +513,13 @@ module ActiveRecord
|
|
517
513
|
target
|
518
514
|
end
|
519
515
|
|
520
|
-
def concat_records(records)
|
516
|
+
def concat_records(records, should_raise = false)
|
521
517
|
result = true
|
522
518
|
|
523
519
|
records.flatten.each do |record|
|
524
520
|
raise_on_type_mismatch!(record)
|
525
521
|
add_to_target(record) do |rec|
|
526
|
-
result &&= insert_record(rec) unless owner.new_record?
|
522
|
+
result &&= insert_record(rec, true, should_raise) unless owner.new_record?
|
527
523
|
end
|
528
524
|
end
|
529
525
|
|
@@ -30,7 +30,6 @@ module ActiveRecord
|
|
30
30
|
unless owner.new_record?
|
31
31
|
records.flatten.each do |record|
|
32
32
|
raise_on_type_mismatch!(record)
|
33
|
-
record.save! if record.new_record?
|
34
33
|
end
|
35
34
|
end
|
36
35
|
|
@@ -40,7 +39,7 @@ module ActiveRecord
|
|
40
39
|
def concat_records(records)
|
41
40
|
ensure_not_nested
|
42
41
|
|
43
|
-
records = super
|
42
|
+
records = super(records, true)
|
44
43
|
|
45
44
|
if owner.new_record? && records
|
46
45
|
records.flatten.each do |record|
|
@@ -106,7 +106,8 @@ module ActiveRecord
|
|
106
106
|
else
|
107
107
|
# If B < A and A defines its own attribute method, then we don't want to overwrite that.
|
108
108
|
defined = method_defined_within?(method_name, superclass, superclass.generated_attribute_methods)
|
109
|
-
|
109
|
+
base_defined = Base.method_defined?(method_name) || Base.private_method_defined?(method_name)
|
110
|
+
defined && !base_defined || super
|
110
111
|
end
|
111
112
|
end
|
112
113
|
|
@@ -301,7 +301,7 @@ module ActiveRecord
|
|
301
301
|
def association_valid?(reflection, record)
|
302
302
|
return true if record.destroyed? || record.marked_for_destruction?
|
303
303
|
|
304
|
-
unless valid = record.valid?
|
304
|
+
unless valid = record.valid?
|
305
305
|
if reflection.options[:autosave]
|
306
306
|
record.errors.each do |attribute, message|
|
307
307
|
attribute = "#{reflection.name}.#{attribute}"
|
@@ -40,7 +40,7 @@ module ActiveRecord
|
|
40
40
|
# index_exists?(:suppliers, :company_id, unique: true)
|
41
41
|
#
|
42
42
|
# # Check an index with a custom name exists
|
43
|
-
# index_exists?(:suppliers, :company_id, name: "idx_company_id"
|
43
|
+
# index_exists?(:suppliers, :company_id, name: "idx_company_id")
|
44
44
|
#
|
45
45
|
def index_exists?(table_name, column_name, options = {})
|
46
46
|
column_names = Array(column_name)
|
@@ -237,8 +237,8 @@ module ActiveRecord
|
|
237
237
|
# hash and merges with the rest of the hash.
|
238
238
|
# Connection details inside of the "url" key win any merge conflicts
|
239
239
|
def resolve_hash_connection(spec)
|
240
|
-
if url
|
241
|
-
connection_hash = resolve_string_connection(url)
|
240
|
+
if spec["url"] && spec["url"] !~ /^jdbc:/
|
241
|
+
connection_hash = resolve_string_connection(spec.delete("url"))
|
242
242
|
spec.merge!(connection_hash)
|
243
243
|
end
|
244
244
|
spec
|
@@ -93,16 +93,12 @@ module ActiveRecord
|
|
93
93
|
# the connection URL. This hash responds to any string key with
|
94
94
|
# resolved connection information.
|
95
95
|
def default_url_hash
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
nil
|
102
|
-
end
|
96
|
+
Hash.new do |hash, key|
|
97
|
+
hash[key] = if key.is_a? String
|
98
|
+
ActiveRecord::ConnectionAdapters::ConnectionSpecification::ConnectionUrlResolver.new(@url).to_hash
|
99
|
+
else
|
100
|
+
nil
|
103
101
|
end
|
104
|
-
else
|
105
|
-
{}
|
106
102
|
end
|
107
103
|
end
|
108
104
|
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module ActiveRecord
|
2
|
+
# Returns the version of the currently loaded ActiveRecord as a <tt>Gem::Version</tt>
|
3
|
+
def self.gem_version
|
4
|
+
Gem::Version.new VERSION::STRING
|
5
|
+
end
|
6
|
+
|
7
|
+
module VERSION
|
8
|
+
MAJOR = 4
|
9
|
+
MINOR = 1
|
10
|
+
TINY = 0
|
11
|
+
PRE = "rc2"
|
12
|
+
|
13
|
+
STRING = [MAJOR, MINOR, TINY, PRE].compact.join(".")
|
14
|
+
end
|
15
|
+
end
|
@@ -64,7 +64,7 @@ module ActiveRecord
|
|
64
64
|
end
|
65
65
|
|
66
66
|
# Returns true if this object hasn't been saved yet -- that is, a record
|
67
|
-
# for the object doesn't exist in the
|
67
|
+
# for the object doesn't exist in the database yet; otherwise, returns false.
|
68
68
|
def new_record?
|
69
69
|
sync_with_transaction_state
|
70
70
|
@new_record
|
@@ -450,6 +450,8 @@ module ActiveRecord
|
|
450
450
|
changed_attributes.except!(*changes.keys)
|
451
451
|
primary_key = self.class.primary_key
|
452
452
|
self.class.unscoped.where(primary_key => self[primary_key]).update_all(changes) == 1
|
453
|
+
else
|
454
|
+
true
|
453
455
|
end
|
454
456
|
end
|
455
457
|
|
@@ -617,7 +617,9 @@ module ActiveRecord
|
|
617
617
|
|
618
618
|
def references_eager_loaded_tables?
|
619
619
|
joined_tables = arel.join_sources.map do |join|
|
620
|
-
|
620
|
+
if join.is_a?(Arel::Nodes::StringJoin)
|
621
|
+
tables_in_string(join.left)
|
622
|
+
else
|
621
623
|
[join.left.table_name, join.left.table_alias]
|
622
624
|
end
|
623
625
|
end
|
@@ -629,5 +631,12 @@ module ActiveRecord
|
|
629
631
|
|
630
632
|
(references_values - joined_tables).any?
|
631
633
|
end
|
634
|
+
|
635
|
+
def tables_in_string(string)
|
636
|
+
return [] if string.blank?
|
637
|
+
# always convert table names to downcase as in Oracle quoted table names are in uppercase
|
638
|
+
# ignore raw_sql_ that is used by Oracle adapter as alias for limit/offset subqueries
|
639
|
+
string.scan(/([a-zA-Z_][.\w]+).?\./).flatten.map{ |s| s.downcase }.uniq - ['raw_sql_']
|
640
|
+
end
|
632
641
|
end
|
633
642
|
end
|
@@ -13,6 +13,7 @@ module ActiveRecord
|
|
13
13
|
def validate_each(record, attribute, value)
|
14
14
|
finder_class = find_finder_class_for(record)
|
15
15
|
table = finder_class.arel_table
|
16
|
+
value = map_enum_attribute(finder_class,attribute,value)
|
16
17
|
value = deserialize_attribute(record, attribute, value)
|
17
18
|
|
18
19
|
relation = build_relation(finder_class, table, attribute, value)
|
@@ -91,6 +92,12 @@ module ActiveRecord
|
|
91
92
|
value = coder.dump value if value && coder
|
92
93
|
value
|
93
94
|
end
|
95
|
+
|
96
|
+
def map_enum_attribute(klass,attribute,value)
|
97
|
+
mapping = klass.enum_mapping_for(attribute.to_s)
|
98
|
+
value = mapping[value] if value && mapping
|
99
|
+
value
|
100
|
+
end
|
94
101
|
end
|
95
102
|
|
96
103
|
module ClassMethods
|
@@ -1,11 +1,8 @@
|
|
1
|
+
require_relative 'gem_version'
|
2
|
+
|
1
3
|
module ActiveRecord
|
2
|
-
# Returns the version of the currently loaded ActiveRecord as a Gem::Version
|
4
|
+
# Returns the version of the currently loaded ActiveRecord as a <tt>Gem::Version</tt>
|
3
5
|
def self.version
|
4
|
-
|
5
|
-
end
|
6
|
-
|
7
|
-
module VERSION #:nodoc:
|
8
|
-
MAJOR, MINOR, TINY, PRE = ActiveRecord.version.segments
|
9
|
-
STRING = ActiveRecord.version.to_s
|
6
|
+
gem_version
|
10
7
|
end
|
11
8
|
end
|
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.0.
|
4
|
+
version: 4.1.0.rc2
|
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-03-25 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.0.
|
19
|
+
version: 4.1.0.rc2
|
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.0.
|
26
|
+
version: 4.1.0.rc2
|
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.0.
|
33
|
+
version: 4.1.0.rc2
|
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.0.
|
40
|
+
version: 4.1.0.rc2
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: arel
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -157,6 +157,7 @@ files:
|
|
157
157
|
- lib/active_record/explain_subscriber.rb
|
158
158
|
- lib/active_record/fixture_set/file.rb
|
159
159
|
- lib/active_record/fixtures.rb
|
160
|
+
- lib/active_record/gem_version.rb
|
160
161
|
- lib/active_record/inheritance.rb
|
161
162
|
- lib/active_record/integration.rb
|
162
163
|
- lib/active_record/locale/en.yml
|