activerecord 5.2.0.beta2 → 5.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 +5 -5
- data/CHANGELOG.md +231 -2
- data/MIT-LICENSE +1 -1
- data/README.rdoc +1 -1
- data/lib/active_record.rb +1 -1
- data/lib/active_record/aggregations.rb +4 -5
- data/lib/active_record/association_relation.rb +2 -2
- data/lib/active_record/associations.rb +18 -12
- data/lib/active_record/associations/alias_tracker.rb +2 -10
- data/lib/active_record/associations/association.rb +1 -1
- data/lib/active_record/associations/belongs_to_association.rb +9 -9
- data/lib/active_record/associations/belongs_to_polymorphic_association.rb +1 -6
- data/lib/active_record/associations/builder/association.rb +2 -2
- data/lib/active_record/associations/builder/belongs_to.rb +7 -3
- data/lib/active_record/associations/collection_association.rb +2 -2
- data/lib/active_record/associations/collection_proxy.rb +1 -1
- data/lib/active_record/associations/has_many_association.rb +1 -1
- data/lib/active_record/associations/has_many_through_association.rb +4 -17
- data/lib/active_record/associations/has_one_through_association.rb +5 -6
- data/lib/active_record/associations/preloader.rb +1 -1
- data/lib/active_record/associations/preloader/association.rb +2 -2
- data/lib/active_record/associations/through_association.rb +22 -9
- data/lib/active_record/attribute_methods.rb +1 -5
- data/lib/active_record/attribute_methods/dirty.rb +2 -4
- data/lib/active_record/attributes.rb +1 -1
- data/lib/active_record/autosave_association.rb +3 -0
- data/lib/active_record/callbacks.rb +2 -2
- data/lib/active_record/collection_cache_key.rb +5 -6
- data/lib/active_record/connection_adapters/abstract/connection_pool.rb +1 -3
- data/lib/active_record/connection_adapters/abstract/database_statements.rb +57 -21
- data/lib/active_record/connection_adapters/abstract/schema_creation.rb +1 -0
- data/lib/active_record/connection_adapters/abstract/schema_definitions.rb +20 -3
- data/lib/active_record/connection_adapters/abstract/schema_statements.rb +55 -15
- data/lib/active_record/connection_adapters/abstract_adapter.rb +19 -6
- data/lib/active_record/connection_adapters/abstract_mysql_adapter.rb +55 -64
- data/lib/active_record/connection_adapters/mysql/database_statements.rb +8 -1
- data/lib/active_record/connection_adapters/mysql/schema_definitions.rb +0 -4
- data/lib/active_record/connection_adapters/mysql/schema_statements.rb +21 -6
- data/lib/active_record/connection_adapters/postgresql/oid/decimal.rb +1 -1
- data/lib/active_record/connection_adapters/postgresql/oid/range.rb +1 -1
- data/lib/active_record/connection_adapters/postgresql/quoting.rb +9 -1
- data/lib/active_record/connection_adapters/postgresql/schema_creation.rb +12 -0
- data/lib/active_record/connection_adapters/postgresql/schema_definitions.rb +13 -4
- data/lib/active_record/connection_adapters/postgresql/schema_statements.rb +170 -48
- data/lib/active_record/connection_adapters/postgresql_adapter.rb +15 -5
- data/lib/active_record/connection_adapters/schema_cache.rb +2 -2
- data/lib/active_record/connection_adapters/sqlite3_adapter.rb +63 -18
- data/lib/active_record/core.rb +12 -3
- data/lib/active_record/enum.rb +2 -0
- data/lib/active_record/fixtures.rb +28 -37
- data/lib/active_record/gem_version.rb +1 -1
- data/lib/active_record/inheritance.rb +3 -4
- data/lib/active_record/log_subscriber.rb +41 -0
- data/lib/active_record/migration.rb +138 -120
- data/lib/active_record/migration/compatibility.rb +20 -0
- data/lib/active_record/model_schema.rb +19 -16
- data/lib/active_record/persistence.rb +8 -11
- data/lib/active_record/railtie.rb +7 -2
- data/lib/active_record/railties/databases.rake +8 -11
- data/lib/active_record/reflection.rb +10 -13
- data/lib/active_record/relation.rb +27 -17
- data/lib/active_record/relation/calculations.rb +17 -12
- data/lib/active_record/relation/finder_methods.rb +30 -37
- data/lib/active_record/relation/merger.rb +30 -2
- data/lib/active_record/relation/predicate_builder.rb +12 -0
- data/lib/active_record/relation/predicate_builder/association_query_value.rb +1 -1
- data/lib/active_record/relation/predicate_builder/polymorphic_array_value.rb +1 -1
- data/lib/active_record/relation/query_methods.rb +14 -24
- data/lib/active_record/relation/spawn_methods.rb +1 -1
- data/lib/active_record/relation/where_clause.rb +16 -2
- data/lib/active_record/relation/where_clause_factory.rb +1 -2
- data/lib/active_record/sanitization.rb +130 -128
- data/lib/active_record/schema.rb +1 -1
- data/lib/active_record/schema_dumper.rb +12 -3
- data/lib/active_record/scoping/named.rb +6 -0
- data/lib/active_record/store.rb +1 -1
- data/lib/active_record/table_metadata.rb +10 -3
- data/lib/active_record/tasks/database_tasks.rb +4 -4
- data/lib/active_record/type_caster/map.rb +1 -1
- metadata +9 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 93d18124cf004be27375ca0f77a70d56b880796ee10d10dada17e2fe8db884e4
|
4
|
+
data.tar.gz: d8a7fbd5fd738a36fb7bbbbddebeb4f1e3ceec661f81fa31a545decd3c30b19c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4b80509910c2c049cbdb41b24babb91bd0562709e4939894b9686d0516fd38e2ab30f0e009cb38205d57e19ab83952b53e1ab1f8e7b8741a4c552e416c1025b9
|
7
|
+
data.tar.gz: 6d848c3decb422926c55d2d9102c2d1e7d5d36c27d0d3b39b0fb6973533283e1e051a687f0da141c2ab8d3b1958b01d1e98c362b56f8455883a6366f7a08bd97
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,232 @@
|
|
1
|
+
## Rails 5.2.0.rc1 (January 30, 2018) ##
|
2
|
+
|
3
|
+
* Deprecate `expand_hash_conditions_for_aggregates` without replacement.
|
4
|
+
Using a `Relation` for performing queries is the prefered API.
|
5
|
+
|
6
|
+
*Ryuta Kamizono*
|
7
|
+
|
8
|
+
* Fix not expanded problem when passing an Array object as argument to the where method using `composed_of` column.
|
9
|
+
|
10
|
+
```
|
11
|
+
david_balance = customers(:david).balance
|
12
|
+
Customer.where(balance: [david_balance]).to_sql
|
13
|
+
|
14
|
+
# Before: WHERE `customers`.`balance` = NULL
|
15
|
+
# After : WHERE `customers`.`balance` = 50
|
16
|
+
```
|
17
|
+
|
18
|
+
Fixes #31723.
|
19
|
+
|
20
|
+
*Yutaro Kanagawa*
|
21
|
+
|
22
|
+
* Fix `count(:all)` with eager loading and having an order other than the driving table.
|
23
|
+
|
24
|
+
Fixes #31783.
|
25
|
+
|
26
|
+
*Ryuta Kamizono*
|
27
|
+
|
28
|
+
* Clear the transaction state when an Active Record object is duped.
|
29
|
+
|
30
|
+
Fixes #31670.
|
31
|
+
|
32
|
+
*Yuriy Ustushenko*
|
33
|
+
|
34
|
+
* Support for PostgreSQL foreign tables.
|
35
|
+
|
36
|
+
*fatkodima*
|
37
|
+
|
38
|
+
* Fix relation merger issue with `left_outer_joins`.
|
39
|
+
|
40
|
+
*Mehmet Emin İNAÇ*
|
41
|
+
|
42
|
+
* Don't allow destroyed object mutation after `save` or `save!` is called.
|
43
|
+
|
44
|
+
*Ryuta Kamizono*
|
45
|
+
|
46
|
+
* Take into account association conditions when deleting through records.
|
47
|
+
|
48
|
+
Fixes #18424.
|
49
|
+
|
50
|
+
*Piotr Jakubowski*
|
51
|
+
|
52
|
+
* Fix nested `has_many :through` associations on unpersisted parent instances.
|
53
|
+
|
54
|
+
For example, if you have
|
55
|
+
|
56
|
+
class Post < ActiveRecord::Base
|
57
|
+
belongs_to :author
|
58
|
+
has_many :books, through: :author
|
59
|
+
has_many :subscriptions, through: :books
|
60
|
+
end
|
61
|
+
|
62
|
+
class Author < ActiveRecord::Base
|
63
|
+
has_one :post
|
64
|
+
has_many :books
|
65
|
+
has_many :subscriptions, through: :books
|
66
|
+
end
|
67
|
+
|
68
|
+
class Book < ActiveRecord::Base
|
69
|
+
belongs_to :author
|
70
|
+
has_many :subscriptions
|
71
|
+
end
|
72
|
+
|
73
|
+
class Subscription < ActiveRecord::Base
|
74
|
+
belongs_to :book
|
75
|
+
end
|
76
|
+
|
77
|
+
Before:
|
78
|
+
|
79
|
+
If `post` is not persisted, then `post.subscriptions` will be empty.
|
80
|
+
|
81
|
+
After:
|
82
|
+
|
83
|
+
If `post` is not persisted, then `post.subscriptions` can be set and used
|
84
|
+
just like it would if `post` were persisted.
|
85
|
+
|
86
|
+
Fixes #16313.
|
87
|
+
|
88
|
+
*Zoltan Kiss*
|
89
|
+
|
90
|
+
* Fixed inconsistency with `first(n)` when used with `limit()`.
|
91
|
+
The `first(n)` finder now respects the `limit()`, making it consistent
|
92
|
+
with `relation.to_a.first(n)`, and also with the behavior of `last(n)`.
|
93
|
+
|
94
|
+
Fixes #23979.
|
95
|
+
|
96
|
+
*Brian Christian*
|
97
|
+
|
98
|
+
* Use `count(:all)` in `HasManyAssociation#count_records` to prevent invalid
|
99
|
+
SQL queries for association counting.
|
100
|
+
|
101
|
+
*Klas Eskilson*
|
102
|
+
|
103
|
+
* Fix to invoke callbacks when using `update_attribute`.
|
104
|
+
|
105
|
+
*Mike Busch*
|
106
|
+
|
107
|
+
* Fix `count(:all)` to correctly work `distinct` with custom SELECT list.
|
108
|
+
|
109
|
+
*Ryuta Kamizono*
|
110
|
+
|
111
|
+
* Using subselect for `delete_all` with `limit` or `offset`.
|
112
|
+
|
113
|
+
*Ryuta Kamizono*
|
114
|
+
|
115
|
+
* Undefine attribute methods on descendants when resetting column
|
116
|
+
information.
|
117
|
+
|
118
|
+
*Chris Salzberg*
|
119
|
+
|
120
|
+
* Log database query callers
|
121
|
+
|
122
|
+
Add `verbose_query_logs` configuration option to display the caller
|
123
|
+
of database queries in the log to facilitate N+1 query resolution
|
124
|
+
and other debugging.
|
125
|
+
|
126
|
+
Enabled in development only for new and upgraded applications. Not
|
127
|
+
recommended for use in the production environment since it relies
|
128
|
+
on Ruby's `Kernel#caller_locations` which is fairly slow.
|
129
|
+
|
130
|
+
*Olivier Lacan*
|
131
|
+
|
132
|
+
* Fix conflicts `counter_cache` with `touch: true` by optimistic locking.
|
133
|
+
|
134
|
+
```
|
135
|
+
# create_table :posts do |t|
|
136
|
+
# t.integer :comments_count, default: 0
|
137
|
+
# t.integer :lock_version
|
138
|
+
# t.timestamps
|
139
|
+
# end
|
140
|
+
class Post < ApplicationRecord
|
141
|
+
end
|
142
|
+
|
143
|
+
# create_table :comments do |t|
|
144
|
+
# t.belongs_to :post
|
145
|
+
# end
|
146
|
+
class Comment < ApplicationRecord
|
147
|
+
belongs_to :post, touch: true, counter_cache: true
|
148
|
+
end
|
149
|
+
```
|
150
|
+
|
151
|
+
Before:
|
152
|
+
```
|
153
|
+
post = Post.create!
|
154
|
+
# => begin transaction
|
155
|
+
INSERT INTO "posts" ("created_at", "updated_at", "lock_version")
|
156
|
+
VALUES ("2017-12-11 21:27:11.387397", "2017-12-11 21:27:11.387397", 0)
|
157
|
+
commit transaction
|
158
|
+
|
159
|
+
comment = Comment.create!(post: post)
|
160
|
+
# => begin transaction
|
161
|
+
INSERT INTO "comments" ("post_id") VALUES (1)
|
162
|
+
|
163
|
+
UPDATE "posts" SET "comments_count" = COALESCE("comments_count", 0) + 1,
|
164
|
+
"lock_version" = COALESCE("lock_version", 0) + 1 WHERE "posts"."id" = 1
|
165
|
+
|
166
|
+
UPDATE "posts" SET "updated_at" = '2017-12-11 21:27:11.398330',
|
167
|
+
"lock_version" = 1 WHERE "posts"."id" = 1 AND "posts"."lock_version" = 0
|
168
|
+
rollback transaction
|
169
|
+
# => ActiveRecord::StaleObjectError: Attempted to touch a stale object: Post.
|
170
|
+
|
171
|
+
Comment.take.destroy!
|
172
|
+
# => begin transaction
|
173
|
+
DELETE FROM "comments" WHERE "comments"."id" = 1
|
174
|
+
|
175
|
+
UPDATE "posts" SET "comments_count" = COALESCE("comments_count", 0) - 1,
|
176
|
+
"lock_version" = COALESCE("lock_version", 0) + 1 WHERE "posts"."id" = 1
|
177
|
+
|
178
|
+
UPDATE "posts" SET "updated_at" = '2017-12-11 21:42:47.785901',
|
179
|
+
"lock_version" = 1 WHERE "posts"."id" = 1 AND "posts"."lock_version" = 0
|
180
|
+
rollback transaction
|
181
|
+
# => ActiveRecord::StaleObjectError: Attempted to touch a stale object: Post.
|
182
|
+
```
|
183
|
+
|
184
|
+
After:
|
185
|
+
```
|
186
|
+
post = Post.create!
|
187
|
+
# => begin transaction
|
188
|
+
INSERT INTO "posts" ("created_at", "updated_at", "lock_version")
|
189
|
+
VALUES ("2017-12-11 21:27:11.387397", "2017-12-11 21:27:11.387397", 0)
|
190
|
+
commit transaction
|
191
|
+
|
192
|
+
comment = Comment.create!(post: post)
|
193
|
+
# => begin transaction
|
194
|
+
INSERT INTO "comments" ("post_id") VALUES (1)
|
195
|
+
|
196
|
+
UPDATE "posts" SET "comments_count" = COALESCE("comments_count", 0) + 1,
|
197
|
+
"lock_version" = COALESCE("lock_version", 0) + 1,
|
198
|
+
"updated_at" = '2017-12-11 21:37:09.802642' WHERE "posts"."id" = 1
|
199
|
+
commit transaction
|
200
|
+
|
201
|
+
comment.destroy!
|
202
|
+
# => begin transaction
|
203
|
+
DELETE FROM "comments" WHERE "comments"."id" = 1
|
204
|
+
|
205
|
+
UPDATE "posts" SET "comments_count" = COALESCE("comments_count", 0) - 1,
|
206
|
+
"lock_version" = COALESCE("lock_version", 0) + 1,
|
207
|
+
"updated_at" = '2017-12-11 21:39:02.685520' WHERE "posts"."id" = 1
|
208
|
+
commit transaction
|
209
|
+
```
|
210
|
+
|
211
|
+
Fixes #31199.
|
212
|
+
|
213
|
+
*bogdanvlviv*
|
214
|
+
|
215
|
+
* Add support for PostgreSQL operator classes to `add_index`.
|
216
|
+
|
217
|
+
Example:
|
218
|
+
|
219
|
+
add_index :users, :name, using: :gist, opclass: { name: :gist_trgm_ops }
|
220
|
+
|
221
|
+
*Greg Navis*
|
222
|
+
|
223
|
+
* Don't allow scopes to be defined which conflict with instance methods on `Relation`.
|
224
|
+
|
225
|
+
Fixes #31120.
|
226
|
+
|
227
|
+
*kinnrot*
|
228
|
+
|
229
|
+
|
1
230
|
## Rails 5.2.0.beta2 (November 28, 2017) ##
|
2
231
|
|
3
232
|
* No changes.
|
@@ -65,7 +294,7 @@
|
|
65
294
|
*bogdanvlviv*
|
66
295
|
|
67
296
|
* Fixed a bug where column orders for an index weren't written to
|
68
|
-
db/schema.rb when using the sqlite adapter.
|
297
|
+
`db/schema.rb` when using the sqlite adapter.
|
69
298
|
|
70
299
|
Fixes #30902.
|
71
300
|
|
@@ -429,7 +658,7 @@
|
|
429
658
|
|
430
659
|
*Ryuta Kamizono*
|
431
660
|
|
432
|
-
* Fix inconsistency with changed attributes when overriding
|
661
|
+
* Fix inconsistency with changed attributes when overriding Active Record attribute reader.
|
433
662
|
|
434
663
|
*bogdanvlviv*
|
435
664
|
|
data/MIT-LICENSE
CHANGED
data/README.rdoc
CHANGED
data/lib/active_record.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
#--
|
4
|
-
# Copyright (c) 2004-
|
4
|
+
# Copyright (c) 2004-2018 David Heinemeier Hansson
|
5
5
|
#
|
6
6
|
# Permission is hereby granted, free of charge, to any person obtaining
|
7
7
|
# a copy of this software and associated documentation files (the
|
@@ -35,7 +35,7 @@ module ActiveRecord
|
|
35
35
|
# the database).
|
36
36
|
#
|
37
37
|
# class Customer < ActiveRecord::Base
|
38
|
-
# composed_of :balance, class_name: "Money", mapping: %w(amount
|
38
|
+
# composed_of :balance, class_name: "Money", mapping: %w(balance amount)
|
39
39
|
# composed_of :address, mapping: [ %w(address_street street), %w(address_city city) ]
|
40
40
|
# end
|
41
41
|
#
|
@@ -177,9 +177,9 @@ module ActiveRecord
|
|
177
177
|
#
|
178
178
|
# Once a #composed_of relationship is specified for a model, records can be loaded from the database
|
179
179
|
# by specifying an instance of the value object in the conditions hash. The following example
|
180
|
-
# finds all customers with +
|
180
|
+
# finds all customers with +address_street+ equal to "May Street" and +address_city+ equal to "Chicago":
|
181
181
|
#
|
182
|
-
# Customer.where(
|
182
|
+
# Customer.where(address: Address.new("May Street", "Chicago"))
|
183
183
|
#
|
184
184
|
module ClassMethods
|
185
185
|
# Adds reader and writer methods for manipulating a value object:
|
@@ -212,8 +212,7 @@ module ActiveRecord
|
|
212
212
|
#
|
213
213
|
# Option examples:
|
214
214
|
# composed_of :temperature, mapping: %w(reading celsius)
|
215
|
-
# composed_of :balance, class_name: "Money", mapping: %w(balance amount)
|
216
|
-
# converter: Proc.new { |balance| balance.to_money }
|
215
|
+
# composed_of :balance, class_name: "Money", mapping: %w(balance amount)
|
217
216
|
# composed_of :address, mapping: [ %w(address_street street), %w(address_city city) ]
|
218
217
|
# composed_of :gps_location
|
219
218
|
# composed_of :gps_location, allow_nil: true
|
@@ -1061,12 +1061,6 @@ module ActiveRecord
|
|
1061
1061
|
# belongs_to :dungeon, inverse_of: :evil_wizard
|
1062
1062
|
# end
|
1063
1063
|
#
|
1064
|
-
# There are limitations to <tt>:inverse_of</tt> support:
|
1065
|
-
#
|
1066
|
-
# * does not work with <tt>:through</tt> associations.
|
1067
|
-
# * does not work with <tt>:polymorphic</tt> associations.
|
1068
|
-
# * inverse associations for #belongs_to associations #has_many are ignored.
|
1069
|
-
#
|
1070
1064
|
# For more information, see the documentation for the +:inverse_of+ option.
|
1071
1065
|
#
|
1072
1066
|
# == Deleting from associations
|
@@ -1279,6 +1273,9 @@ module ActiveRecord
|
|
1279
1273
|
# Specify the foreign key used for the association. By default this is guessed to be the name
|
1280
1274
|
# of this class in lower-case and "_id" suffixed. So a Person class that makes a #has_many
|
1281
1275
|
# association will use "person_id" as the default <tt>:foreign_key</tt>.
|
1276
|
+
#
|
1277
|
+
# If you are going to modify the association (rather than just read from it), then it is
|
1278
|
+
# a good idea to set the <tt>:inverse_of</tt> option.
|
1282
1279
|
# [:foreign_type]
|
1283
1280
|
# Specify the column used to store the associated object's type, if this is a polymorphic
|
1284
1281
|
# association. By default this is guessed to be the name of the polymorphic association
|
@@ -1352,8 +1349,7 @@ module ActiveRecord
|
|
1352
1349
|
# <tt>:autosave</tt> to <tt>true</tt>.
|
1353
1350
|
# [:inverse_of]
|
1354
1351
|
# Specifies the name of the #belongs_to association on the associated object
|
1355
|
-
# that is the inverse of this #has_many association.
|
1356
|
-
# with <tt>:through</tt> or <tt>:as</tt> options.
|
1352
|
+
# that is the inverse of this #has_many association.
|
1357
1353
|
# See ActiveRecord::Associations::ClassMethods's overview on Bi-directional associations for more detail.
|
1358
1354
|
# [:extend]
|
1359
1355
|
# Specifies a module or array of modules that will be extended into the association object returned.
|
@@ -1449,6 +1445,9 @@ module ActiveRecord
|
|
1449
1445
|
# Specify the foreign key used for the association. By default this is guessed to be the name
|
1450
1446
|
# of this class in lower-case and "_id" suffixed. So a Person class that makes a #has_one association
|
1451
1447
|
# will use "person_id" as the default <tt>:foreign_key</tt>.
|
1448
|
+
#
|
1449
|
+
# If you are going to modify the association (rather than just read from it), then it is
|
1450
|
+
# a good idea to set the <tt>:inverse_of</tt> option.
|
1452
1451
|
# [:foreign_type]
|
1453
1452
|
# Specify the column used to store the associated object's type, if this is a polymorphic
|
1454
1453
|
# association. By default this is guessed to be the name of the polymorphic association
|
@@ -1464,6 +1463,9 @@ module ActiveRecord
|
|
1464
1463
|
# <tt>:primary_key</tt>, and <tt>:foreign_key</tt> are ignored, as the association uses the
|
1465
1464
|
# source reflection. You can only use a <tt>:through</tt> query through a #has_one
|
1466
1465
|
# or #belongs_to association on the join model.
|
1466
|
+
#
|
1467
|
+
# If you are going to modify the association (rather than just read from it), then it is
|
1468
|
+
# a good idea to set the <tt>:inverse_of</tt> option.
|
1467
1469
|
# [:source]
|
1468
1470
|
# Specifies the source association name used by #has_one <tt>:through</tt> queries.
|
1469
1471
|
# Only use it if the name cannot be inferred from the association.
|
@@ -1484,8 +1486,7 @@ module ActiveRecord
|
|
1484
1486
|
# <tt>:autosave</tt> to <tt>true</tt>.
|
1485
1487
|
# [:inverse_of]
|
1486
1488
|
# Specifies the name of the #belongs_to association on the associated object
|
1487
|
-
# that is the inverse of this #has_one association.
|
1488
|
-
# with <tt>:through</tt> or <tt>:as</tt> options.
|
1489
|
+
# that is the inverse of this #has_one association.
|
1489
1490
|
# See ActiveRecord::Associations::ClassMethods's overview on Bi-directional associations for more detail.
|
1490
1491
|
# [:required]
|
1491
1492
|
# When set to +true+, the association will also have its presence validated.
|
@@ -1570,6 +1571,9 @@ module ActiveRecord
|
|
1570
1571
|
# association will use "person_id" as the default <tt>:foreign_key</tt>. Similarly,
|
1571
1572
|
# <tt>belongs_to :favorite_person, class_name: "Person"</tt> will use a foreign key
|
1572
1573
|
# of "favorite_person_id".
|
1574
|
+
#
|
1575
|
+
# If you are going to modify the association (rather than just read from it), then it is
|
1576
|
+
# a good idea to set the <tt>:inverse_of</tt> option.
|
1573
1577
|
# [:foreign_type]
|
1574
1578
|
# Specify the column used to store the associated object's type, if this is a polymorphic
|
1575
1579
|
# association. By default this is guessed to be the name of the association with a "_type"
|
@@ -1619,8 +1623,7 @@ module ActiveRecord
|
|
1619
1623
|
# +after_commit+ and +after_rollback+ callbacks are executed.
|
1620
1624
|
# [:inverse_of]
|
1621
1625
|
# Specifies the name of the #has_one or #has_many association on the associated
|
1622
|
-
# object that is the inverse of this #belongs_to association.
|
1623
|
-
# combination with the <tt>:polymorphic</tt> options.
|
1626
|
+
# object that is the inverse of this #belongs_to association.
|
1624
1627
|
# See ActiveRecord::Associations::ClassMethods's overview on Bi-directional associations for more detail.
|
1625
1628
|
# [:optional]
|
1626
1629
|
# When set to +true+, the association will not have its presence validated.
|
@@ -1789,6 +1792,9 @@ module ActiveRecord
|
|
1789
1792
|
# of this class in lower-case and "_id" suffixed. So a Person class that makes
|
1790
1793
|
# a #has_and_belongs_to_many association to Project will use "person_id" as the
|
1791
1794
|
# default <tt>:foreign_key</tt>.
|
1795
|
+
#
|
1796
|
+
# If you are going to modify the association (rather than just read from it), then it is
|
1797
|
+
# a good idea to set the <tt>:inverse_of</tt> option.
|
1792
1798
|
# [:association_foreign_key]
|
1793
1799
|
# Specify the foreign key used for the association on the receiving side of the association.
|
1794
1800
|
# By default this is guessed to be the name of the associated class in lower-case and "_id" suffixed.
|
@@ -30,20 +30,12 @@ module ActiveRecord
|
|
30
30
|
join.left.scan(
|
31
31
|
/JOIN(?:\s+\w+)?\s+(?:\S+\s+)?(?:#{quoted_name}|#{name})\sON/i
|
32
32
|
).size
|
33
|
-
elsif join.
|
33
|
+
elsif join.is_a?(Arel::Nodes::Join)
|
34
34
|
join.left.name == name ? 1 : 0
|
35
35
|
elsif join.is_a?(Hash)
|
36
36
|
join.fetch(name, 0)
|
37
37
|
else
|
38
|
-
|
39
|
-
#
|
40
|
-
# activerecord/test/cases/associations/cascaded_eager_loading_test.rb:37
|
41
|
-
# with :posts
|
42
|
-
#
|
43
|
-
# activerecord/test/cases/associations/eager_test.rb:1133
|
44
|
-
# with :comments
|
45
|
-
#
|
46
|
-
0
|
38
|
+
raise ArgumentError, "joins list should be initialized by list of Arel::Nodes::Join"
|
47
39
|
end
|
48
40
|
end
|
49
41
|
|
@@ -124,7 +124,7 @@ module ActiveRecord
|
|
124
124
|
# Can be overridden (i.e. in ThroughAssociation) to merge in other scopes (i.e. the
|
125
125
|
# through association's scope)
|
126
126
|
def target_scope
|
127
|
-
AssociationRelation.create(klass,
|
127
|
+
AssociationRelation.create(klass, self).merge!(klass.all)
|
128
128
|
end
|
129
129
|
|
130
130
|
def extensions
|