activerecord 6.0.0.beta3 → 6.0.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 +286 -6
- data/README.rdoc +3 -1
- data/lib/active_record.rb +0 -1
- data/lib/active_record/associations.rb +3 -2
- data/lib/active_record/associations/association.rb +1 -1
- data/lib/active_record/associations/builder/association.rb +14 -18
- data/lib/active_record/associations/builder/belongs_to.rb +5 -2
- data/lib/active_record/associations/builder/collection_association.rb +3 -13
- data/lib/active_record/associations/builder/has_many.rb +2 -0
- data/lib/active_record/associations/builder/has_one.rb +35 -1
- data/lib/active_record/associations/builder/singular_association.rb +2 -0
- data/lib/active_record/associations/collection_proxy.rb +1 -1
- data/lib/active_record/associations/has_many_through_association.rb +4 -11
- data/lib/active_record/associations/preloader.rb +11 -6
- data/lib/active_record/associations/preloader/association.rb +32 -30
- data/lib/active_record/associations/preloader/through_association.rb +48 -28
- data/lib/active_record/attribute_methods.rb +4 -3
- data/lib/active_record/attribute_methods/before_type_cast.rb +4 -1
- data/lib/active_record/attribute_methods/dirty.rb +42 -14
- data/lib/active_record/attribute_methods/primary_key.rb +7 -15
- data/lib/active_record/attribute_methods/query.rb +2 -3
- data/lib/active_record/attribute_methods/read.rb +3 -9
- data/lib/active_record/attribute_methods/write.rb +6 -12
- data/lib/active_record/attributes.rb +13 -0
- data/lib/active_record/autosave_association.rb +13 -3
- data/lib/active_record/base.rb +0 -1
- data/lib/active_record/connection_adapters/abstract/connection_pool.rb +1 -0
- data/lib/active_record/connection_adapters/abstract/database_limits.rb +8 -4
- data/lib/active_record/connection_adapters/abstract/database_statements.rb +84 -61
- data/lib/active_record/connection_adapters/abstract/query_cache.rb +2 -1
- data/lib/active_record/connection_adapters/abstract/quoting.rb +10 -6
- data/lib/active_record/connection_adapters/abstract/schema_definitions.rb +4 -7
- data/lib/active_record/connection_adapters/abstract/schema_statements.rb +70 -14
- data/lib/active_record/connection_adapters/abstract_adapter.rb +56 -11
- data/lib/active_record/connection_adapters/abstract_mysql_adapter.rb +65 -69
- data/lib/active_record/connection_adapters/column.rb +17 -13
- data/lib/active_record/connection_adapters/mysql/database_statements.rb +45 -7
- data/lib/active_record/connection_adapters/mysql/schema_dumper.rb +4 -4
- data/lib/active_record/connection_adapters/mysql/schema_statements.rb +9 -6
- data/lib/active_record/connection_adapters/mysql/type_metadata.rb +6 -10
- data/lib/active_record/connection_adapters/mysql2_adapter.rb +6 -2
- data/lib/active_record/connection_adapters/postgresql/column.rb +17 -30
- data/lib/active_record/connection_adapters/postgresql/database_statements.rb +5 -1
- data/lib/active_record/connection_adapters/postgresql/schema_statements.rb +34 -38
- data/lib/active_record/connection_adapters/postgresql/type_metadata.rb +23 -27
- data/lib/active_record/connection_adapters/postgresql_adapter.rb +57 -27
- data/lib/active_record/connection_adapters/schema_cache.rb +32 -14
- data/lib/active_record/connection_adapters/sql_type_metadata.rb +11 -8
- data/lib/active_record/connection_adapters/sqlite3/database_statements.rb +118 -0
- data/lib/active_record/connection_adapters/sqlite3/schema_statements.rb +2 -2
- data/lib/active_record/connection_adapters/sqlite3_adapter.rb +50 -112
- data/lib/active_record/connection_handling.rb +17 -10
- data/lib/active_record/core.rb +15 -20
- data/lib/active_record/database_configurations.rb +14 -14
- data/lib/active_record/database_configurations/hash_config.rb +11 -11
- data/lib/active_record/database_configurations/url_config.rb +12 -12
- data/lib/active_record/dynamic_matchers.rb +1 -1
- data/lib/active_record/enum.rb +6 -0
- data/lib/active_record/errors.rb +1 -1
- data/lib/active_record/gem_version.rb +1 -1
- data/lib/active_record/insert_all.rb +180 -0
- data/lib/active_record/integration.rb +13 -1
- data/lib/active_record/internal_metadata.rb +5 -1
- data/lib/active_record/locking/optimistic.rb +3 -4
- data/lib/active_record/log_subscriber.rb +1 -1
- data/lib/active_record/migration.rb +25 -18
- data/lib/active_record/migration/command_recorder.rb +28 -14
- data/lib/active_record/migration/compatibility.rb +10 -0
- data/lib/active_record/persistence.rb +206 -13
- data/lib/active_record/querying.rb +17 -12
- data/lib/active_record/railties/databases.rake +68 -6
- data/lib/active_record/reflection.rb +2 -2
- data/lib/active_record/relation.rb +98 -20
- data/lib/active_record/relation/calculations.rb +39 -39
- data/lib/active_record/relation/delegation.rb +22 -30
- data/lib/active_record/relation/finder_methods.rb +3 -9
- data/lib/active_record/relation/merger.rb +7 -16
- data/lib/active_record/relation/query_methods.rb +153 -38
- data/lib/active_record/relation/where_clause.rb +9 -5
- data/lib/active_record/sanitization.rb +3 -2
- data/lib/active_record/schema_dumper.rb +5 -0
- data/lib/active_record/schema_migration.rb +1 -1
- data/lib/active_record/scoping/default.rb +6 -7
- data/lib/active_record/scoping/named.rb +1 -1
- data/lib/active_record/statement_cache.rb +2 -2
- data/lib/active_record/store.rb +48 -0
- data/lib/active_record/table_metadata.rb +3 -3
- data/lib/active_record/tasks/database_tasks.rb +36 -1
- data/lib/active_record/touch_later.rb +2 -2
- data/lib/active_record/transactions.rb +52 -41
- data/lib/active_record/validations/uniqueness.rb +3 -5
- data/lib/arel/insert_manager.rb +3 -3
- data/lib/arel/nodes.rb +2 -1
- data/lib/arel/nodes/comment.rb +29 -0
- data/lib/arel/nodes/select_core.rb +16 -12
- data/lib/arel/nodes/unary.rb +1 -0
- data/lib/arel/nodes/values_list.rb +2 -17
- data/lib/arel/select_manager.rb +10 -10
- data/lib/arel/visitors/depth_first.rb +6 -1
- data/lib/arel/visitors/dot.rb +7 -2
- data/lib/arel/visitors/ibm_db.rb +13 -0
- data/lib/arel/visitors/informix.rb +6 -0
- data/lib/arel/visitors/mssql.rb +15 -1
- data/lib/arel/visitors/oracle12.rb +4 -5
- data/lib/arel/visitors/postgresql.rb +4 -10
- data/lib/arel/visitors/to_sql.rb +87 -108
- data/lib/rails/generators/active_record/migration/migration_generator.rb +1 -1
- data/lib/rails/generators/active_record/migration/templates/create_table_migration.rb.tt +1 -1
- data/lib/rails/generators/active_record/migration/templates/migration.rb.tt +4 -2
- data/lib/rails/generators/active_record/model/model_generator.rb +1 -1
- data/lib/rails/generators/active_record/model/templates/model.rb.tt +10 -1
- metadata +12 -11
- data/lib/active_record/collection_cache_key.rb +0 -53
- data/lib/arel/nodes/values.rb +0 -16
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: eef34b080ecf453eb7de6b2b21fd1664c907b4a56ce8b34077da04422c14b528
|
4
|
+
data.tar.gz: 1f03004e330e5825d91500dd14584568fbbb647dd05a91d750d1f84ee83501b1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a9368890aab4ae0d88d495501d21a21481a4ccd891c7ddd65219cfb18fd10418456959c9e1b24edc13ba0200ee9dd96fa0deea56da2214d03e838293625782c3
|
7
|
+
data.tar.gz: a5c09c091e320de679561ef84cd58833d8a3b4d477aa98f6d917fb494b20bbf3d55dfb6e3167e91a613f8868844a32ae71364b7fb35d5221ecf526066e8371cb
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,283 @@
|
|
1
|
+
## Rails 6.0.0.rc1 (April 24, 2019) ##
|
2
|
+
|
3
|
+
* Add `touch` option to `has_one` association.
|
4
|
+
|
5
|
+
*Abhay Nikam*
|
6
|
+
|
7
|
+
* Deprecate `where.not` working as NOR and will be changed to NAND in Rails 6.1.
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
all = [treasures(:diamond), treasures(:sapphire), cars(:honda), treasures(:sapphire)]
|
11
|
+
assert_equal all, PriceEstimate.all.map(&:estimate_of)
|
12
|
+
```
|
13
|
+
|
14
|
+
In Rails 6.0:
|
15
|
+
|
16
|
+
```ruby
|
17
|
+
sapphire = treasures(:sapphire)
|
18
|
+
|
19
|
+
nor = all.reject { |e|
|
20
|
+
e.estimate_of_type == sapphire.class.polymorphic_name
|
21
|
+
}.reject { |e|
|
22
|
+
e.estimate_of_id == sapphire.id
|
23
|
+
}
|
24
|
+
assert_equal [cars(:honda)], nor
|
25
|
+
|
26
|
+
without_sapphire = PriceEstimate.where.not(
|
27
|
+
estimate_of_type: sapphire.class.polymorphic_name, estimate_of_id: sapphire.id
|
28
|
+
)
|
29
|
+
assert_equal nor, without_sapphire.map(&:estimate_of)
|
30
|
+
```
|
31
|
+
|
32
|
+
In Rails 6.1:
|
33
|
+
|
34
|
+
```ruby
|
35
|
+
sapphire = treasures(:sapphire)
|
36
|
+
|
37
|
+
nand = all - [sapphire]
|
38
|
+
assert_equal [treasures(:diamond), cars(:honda)], nand
|
39
|
+
|
40
|
+
without_sapphire = PriceEstimate.where.not(
|
41
|
+
estimate_of_type: sapphire.class.polymorphic_name, estimate_of_id: sapphire.id
|
42
|
+
)
|
43
|
+
assert_equal nand, without_sapphire.map(&:estimate_of)
|
44
|
+
```
|
45
|
+
|
46
|
+
*Ryuta Kamizono*
|
47
|
+
|
48
|
+
* Fix dirty tracking after rollback.
|
49
|
+
|
50
|
+
Fixes #15018, #30167, #33868.
|
51
|
+
|
52
|
+
*Ryuta Kamizono*
|
53
|
+
|
54
|
+
* Add `ActiveRecord::Relation#cache_version` to support recyclable cache keys via
|
55
|
+
the versioned entries in `ActiveSupport::Cache`. This also means that
|
56
|
+
`ActiveRecord::Relation#cache_key` will now return a stable key that does not
|
57
|
+
include the max timestamp or count any more.
|
58
|
+
|
59
|
+
NOTE: This feature is turned off by default, and `cache_key` will still return
|
60
|
+
cache keys with timestamps until you set `ActiveRecord::Base.collection_cache_versioning = true`.
|
61
|
+
That's the setting for all new apps on Rails 6.0+
|
62
|
+
|
63
|
+
*Lachlan Sylvester*
|
64
|
+
|
65
|
+
* Fix dirty tracking for `touch` to track saved changes.
|
66
|
+
|
67
|
+
Fixes #33429.
|
68
|
+
|
69
|
+
*Ryuta Kamzono*
|
70
|
+
|
71
|
+
* `change_column_comment` and `change_table_comment` are invertible only if
|
72
|
+
`to` and `from` options are specified.
|
73
|
+
|
74
|
+
*Yoshiyuki Kinjo*
|
75
|
+
|
76
|
+
* Don't call commit/rollback callbacks when a record isn't saved.
|
77
|
+
|
78
|
+
Fixes #29747.
|
79
|
+
|
80
|
+
*Ryuta Kamizono*
|
81
|
+
|
82
|
+
* Fix circular `autosave: true` causes invalid records to be saved.
|
83
|
+
|
84
|
+
Prior to the fix, when there was a circular series of `autosave: true`
|
85
|
+
associations, the callback for a `has_many` association was run while
|
86
|
+
another instance of the same callback on the same association hadn't
|
87
|
+
finished running. When control returned to the first instance of the
|
88
|
+
callback, the instance variable had changed, and subsequent associated
|
89
|
+
records weren't saved correctly. Specifically, the ID field for the
|
90
|
+
`belongs_to` corresponding to the `has_many` was `nil`.
|
91
|
+
|
92
|
+
Fixes #28080.
|
93
|
+
|
94
|
+
*Larry Reid*
|
95
|
+
|
96
|
+
* Raise `ArgumentError` for invalid `:limit` and `:precision` like as other options.
|
97
|
+
|
98
|
+
Before:
|
99
|
+
|
100
|
+
```ruby
|
101
|
+
add_column :items, :attr1, :binary, size: 10 # => ArgumentError
|
102
|
+
add_column :items, :attr2, :decimal, scale: 10 # => ArgumentError
|
103
|
+
add_column :items, :attr3, :integer, limit: 10 # => ActiveRecordError
|
104
|
+
add_column :items, :attr4, :datetime, precision: 10 # => ActiveRecordError
|
105
|
+
```
|
106
|
+
|
107
|
+
After:
|
108
|
+
|
109
|
+
```ruby
|
110
|
+
add_column :items, :attr1, :binary, size: 10 # => ArgumentError
|
111
|
+
add_column :items, :attr2, :decimal, scale: 10 # => ArgumentError
|
112
|
+
add_column :items, :attr3, :integer, limit: 10 # => ArgumentError
|
113
|
+
add_column :items, :attr4, :datetime, precision: 10 # => ArgumentError
|
114
|
+
```
|
115
|
+
|
116
|
+
*Ryuta Kamizono*
|
117
|
+
|
118
|
+
* Association loading isn't to be affected by scoping consistently
|
119
|
+
whether preloaded / eager loaded or not, with the exception of `unscoped`.
|
120
|
+
|
121
|
+
Before:
|
122
|
+
|
123
|
+
```ruby
|
124
|
+
Post.where("1=0").scoping do
|
125
|
+
Comment.find(1).post # => nil
|
126
|
+
Comment.preload(:post).find(1).post # => #<Post id: 1, ...>
|
127
|
+
Comment.eager_load(:post).find(1).post # => #<Post id: 1, ...>
|
128
|
+
end
|
129
|
+
```
|
130
|
+
|
131
|
+
After:
|
132
|
+
|
133
|
+
```ruby
|
134
|
+
Post.where("1=0").scoping do
|
135
|
+
Comment.find(1).post # => #<Post id: 1, ...>
|
136
|
+
Comment.preload(:post).find(1).post # => #<Post id: 1, ...>
|
137
|
+
Comment.eager_load(:post).find(1).post # => #<Post id: 1, ...>
|
138
|
+
end
|
139
|
+
```
|
140
|
+
|
141
|
+
Fixes #34638, #35398.
|
142
|
+
|
143
|
+
*Ryuta Kamizono*
|
144
|
+
|
145
|
+
* Add `rails db:prepare` to migrate or setup a database.
|
146
|
+
|
147
|
+
Runs `db:migrate` if the database exists or `db:setup` if it doesn't.
|
148
|
+
|
149
|
+
*Roberto Miranda*
|
150
|
+
|
151
|
+
* Add `after_save_commit` callback as shortcut for `after_commit :hook, on: [ :create, :update ]`.
|
152
|
+
|
153
|
+
*DHH*
|
154
|
+
|
155
|
+
* Assign all attributes before calling `build` to ensure the child record is visible in
|
156
|
+
`before_add` and `after_add` callbacks for `has_many :through` associations.
|
157
|
+
|
158
|
+
Fixes #33249.
|
159
|
+
|
160
|
+
*Ryan H. Kerr*
|
161
|
+
|
162
|
+
* Add `ActiveRecord::Relation#extract_associated` for extracting associated records from a relation.
|
163
|
+
|
164
|
+
```
|
165
|
+
account.memberships.extract_associated(:user)
|
166
|
+
# => Returns collection of User records
|
167
|
+
```
|
168
|
+
|
169
|
+
*DHH*
|
170
|
+
|
171
|
+
* Add `ActiveRecord::Relation#annotate` for adding SQL comments to its queries.
|
172
|
+
|
173
|
+
For example:
|
174
|
+
|
175
|
+
```
|
176
|
+
Post.where(id: 123).annotate("this is a comment").to_sql
|
177
|
+
# SELECT "posts".* FROM "posts" WHERE "posts"."id" = 123 /* this is a comment */
|
178
|
+
```
|
179
|
+
|
180
|
+
This can be useful in instrumentation or other analysis of issued queries.
|
181
|
+
|
182
|
+
*Matt Yoho*
|
183
|
+
|
184
|
+
* Support Optimizer Hints.
|
185
|
+
|
186
|
+
In most databases, a way to control the optimizer is by using optimizer hints,
|
187
|
+
which can be specified within individual statements.
|
188
|
+
|
189
|
+
Example (for MySQL):
|
190
|
+
|
191
|
+
Topic.optimizer_hints("MAX_EXECUTION_TIME(50000)", "NO_INDEX_MERGE(topics)")
|
192
|
+
# SELECT /*+ MAX_EXECUTION_TIME(50000) NO_INDEX_MERGE(topics) */ `topics`.* FROM `topics`
|
193
|
+
|
194
|
+
Example (for PostgreSQL with pg_hint_plan):
|
195
|
+
|
196
|
+
Topic.optimizer_hints("SeqScan(topics)", "Parallel(topics 8)")
|
197
|
+
# SELECT /*+ SeqScan(topics) Parallel(topics 8) */ "topics".* FROM "topics"
|
198
|
+
|
199
|
+
See also:
|
200
|
+
|
201
|
+
* https://dev.mysql.com/doc/refman/8.0/en/optimizer-hints.html
|
202
|
+
* https://pghintplan.osdn.jp/pg_hint_plan.html
|
203
|
+
* https://docs.oracle.com/en/database/oracle/oracle-database/12.2/tgsql/influencing-the-optimizer.html
|
204
|
+
* https://docs.microsoft.com/en-us/sql/t-sql/queries/hints-transact-sql-query?view=sql-server-2017
|
205
|
+
* https://www.ibm.com/support/knowledgecenter/en/SSEPGG_11.1.0/com.ibm.db2.luw.admin.perf.doc/doc/c0070117.html
|
206
|
+
|
207
|
+
*Ryuta Kamizono*
|
208
|
+
|
209
|
+
* Fix query attribute method on user-defined attribute to be aware of typecasted value.
|
210
|
+
|
211
|
+
For example, the following code no longer return false as casted non-empty string:
|
212
|
+
|
213
|
+
```
|
214
|
+
class Post < ActiveRecord::Base
|
215
|
+
attribute :user_defined_text, :text
|
216
|
+
end
|
217
|
+
|
218
|
+
Post.new(user_defined_text: "false").user_defined_text? # => true
|
219
|
+
```
|
220
|
+
|
221
|
+
*Yuji Kamijima*
|
222
|
+
|
223
|
+
* Quote empty ranges like other empty enumerables.
|
224
|
+
|
225
|
+
*Patrick Rebsch*
|
226
|
+
|
227
|
+
* Add `insert_all`/`insert_all!`/`upsert_all` methods to `ActiveRecord::Persistence`,
|
228
|
+
allowing bulk inserts akin to the bulk updates provided by `update_all` and
|
229
|
+
bulk deletes by `delete_all`.
|
230
|
+
|
231
|
+
Supports skipping or upserting duplicates through the `ON CONFLICT` syntax
|
232
|
+
for PostgreSQL (9.5+) and SQLite (3.24+) and `ON DUPLICATE KEY UPDATE` syntax
|
233
|
+
for MySQL.
|
234
|
+
|
235
|
+
*Bob Lail*
|
236
|
+
|
237
|
+
* Add `rails db:seed:replant` that truncates tables of each database
|
238
|
+
for current environment and loads the seeds.
|
239
|
+
|
240
|
+
*bogdanvlviv*, *DHH*
|
241
|
+
|
242
|
+
* Add `ActiveRecord::Base.connection.truncate` for SQLite3 adapter.
|
243
|
+
|
244
|
+
*bogdanvlviv*
|
245
|
+
|
246
|
+
* Deprecate mismatched collation comparison for uniqueness validator.
|
247
|
+
|
248
|
+
Uniqueness validator will no longer enforce case sensitive comparison in Rails 6.1.
|
249
|
+
To continue case sensitive comparison on the case insensitive column,
|
250
|
+
pass `case_sensitive: true` option explicitly to the uniqueness validator.
|
251
|
+
|
252
|
+
*Ryuta Kamizono*
|
253
|
+
|
254
|
+
* Add `reselect` method. This is a short-hand for `unscope(:select).select(fields)`.
|
255
|
+
|
256
|
+
Fixes #27340.
|
257
|
+
|
258
|
+
*Willian Gustavo Veiga*
|
259
|
+
|
260
|
+
* Add negative scopes for all enum values.
|
261
|
+
|
262
|
+
Example:
|
263
|
+
|
264
|
+
class Post < ActiveRecord::Base
|
265
|
+
enum status: %i[ drafted active trashed ]
|
266
|
+
end
|
267
|
+
|
268
|
+
Post.not_drafted # => where.not(status: :drafted)
|
269
|
+
Post.not_active # => where.not(status: :active)
|
270
|
+
Post.not_trashed # => where.not(status: :trashed)
|
271
|
+
|
272
|
+
*DHH*
|
273
|
+
|
274
|
+
* Fix different `count` calculation when using `size` with manual `select` with DISTINCT.
|
275
|
+
|
276
|
+
Fixes #35214.
|
277
|
+
|
278
|
+
*Juani Villarejo*
|
279
|
+
|
280
|
+
|
1
281
|
## Rails 6.0.0.beta3 (March 11, 2019) ##
|
2
282
|
|
3
283
|
* No changes.
|
@@ -222,7 +502,7 @@
|
|
222
502
|
|
223
503
|
*Gannon McGibbon*
|
224
504
|
|
225
|
-
* Cached columns_hash fields should be excluded from ResultSet#column_types
|
505
|
+
* Cached `columns_hash` fields should be excluded from `ResultSet#column_types`.
|
226
506
|
|
227
507
|
PR #34528 addresses the inconsistent behaviour when attribute is defined for an ignored column. The following test
|
228
508
|
was passing for SQLite and MySQL, but failed for PostgreSQL:
|
@@ -253,12 +533,12 @@
|
|
253
533
|
|
254
534
|
* Make the implicit order column configurable.
|
255
535
|
|
256
|
-
When calling ordered finder methods such as
|
536
|
+
When calling ordered finder methods such as `first` or `last` without an
|
257
537
|
explicit order clause, ActiveRecord sorts records by primary key. This can
|
258
538
|
result in unpredictable and surprising behaviour when the primary key is
|
259
539
|
not an auto-incrementing integer, for example when it's a UUID. This change
|
260
540
|
makes it possible to override the column used for implicit ordering such
|
261
|
-
that
|
541
|
+
that `first` and `last` will return more predictable results.
|
262
542
|
|
263
543
|
Example:
|
264
544
|
|
@@ -328,7 +608,7 @@
|
|
328
608
|
|
329
609
|
*Sean Griffin*
|
330
610
|
|
331
|
-
* Add support for hash and
|
611
|
+
* Add support for hash and URL configs in database hash of `ActiveRecord::Base.connected_to`.
|
332
612
|
|
333
613
|
````
|
334
614
|
User.connected_to(database: { writing: "postgres://foo" }) do
|
@@ -404,10 +684,10 @@
|
|
404
684
|
|
405
685
|
* Enum raises on invalid definition values
|
406
686
|
|
407
|
-
When defining a Hash enum it can be easy to use [] instead of {}
|
687
|
+
When defining a Hash enum it can be easy to use `[]` instead of `{}`. This
|
408
688
|
commit checks that only valid definition values are provided, those can
|
409
689
|
be a Hash, an array of Symbols or an array of Strings. Otherwise it
|
410
|
-
raises an ArgumentError
|
690
|
+
raises an `ArgumentError`.
|
411
691
|
|
412
692
|
Fixes #33961
|
413
693
|
|
data/README.rdoc
CHANGED
@@ -13,6 +13,8 @@ columns. Although these mappings can be defined explicitly, it's recommended
|
|
13
13
|
to follow naming conventions, especially when getting started with the
|
14
14
|
library.
|
15
15
|
|
16
|
+
You can read more about Active Record in the {Active Record Basics}[https://edgeguides.rubyonrails.org/active_record_basics.html] guide.
|
17
|
+
|
16
18
|
A short rundown of some of the major features:
|
17
19
|
|
18
20
|
* Automated mapping between classes and tables, attributes and columns.
|
@@ -206,7 +208,7 @@ Active Record is released under the MIT license:
|
|
206
208
|
|
207
209
|
API documentation is at:
|
208
210
|
|
209
|
-
*
|
211
|
+
* https://api.rubyonrails.org
|
210
212
|
|
211
213
|
Bug reports for the Ruby on Rails project can be filed here:
|
212
214
|
|
data/lib/active_record.rb
CHANGED
@@ -703,8 +703,9 @@ module ActiveRecord
|
|
703
703
|
# #belongs_to associations.
|
704
704
|
#
|
705
705
|
# Extra options on the associations, as defined in the
|
706
|
-
# <tt>AssociationReflection::INVALID_AUTOMATIC_INVERSE_OPTIONS</tt>
|
707
|
-
# also prevent the association's inverse
|
706
|
+
# <tt>AssociationReflection::INVALID_AUTOMATIC_INVERSE_OPTIONS</tt>
|
707
|
+
# constant, or a custom scope, will also prevent the association's inverse
|
708
|
+
# from being found automatically.
|
708
709
|
#
|
709
710
|
# The automatic guessing of the inverse association uses a heuristic based
|
710
711
|
# on the name of the class, so it may not work for all associations,
|
@@ -225,7 +225,7 @@ module ActiveRecord
|
|
225
225
|
# Can be overridden (i.e. in ThroughAssociation) to merge in other scopes (i.e. the
|
226
226
|
# through association's scope)
|
227
227
|
def target_scope
|
228
|
-
AssociationRelation.create(klass, self).merge!(klass.
|
228
|
+
AssociationRelation.create(klass, self).merge!(klass.scope_for_association)
|
229
229
|
end
|
230
230
|
|
231
231
|
def scope_for_create
|
@@ -27,40 +27,32 @@ module ActiveRecord::Associations::Builder # :nodoc:
|
|
27
27
|
"Please choose a different association name."
|
28
28
|
end
|
29
29
|
|
30
|
-
|
31
|
-
reflection = create_reflection model, name, scope, options, extension
|
30
|
+
reflection = create_reflection(model, name, scope, options, &block)
|
32
31
|
define_accessors model, reflection
|
33
32
|
define_callbacks model, reflection
|
34
33
|
define_validations model, reflection
|
35
34
|
reflection
|
36
35
|
end
|
37
36
|
|
38
|
-
def self.create_reflection(model, name, scope, options,
|
37
|
+
def self.create_reflection(model, name, scope, options, &block)
|
39
38
|
raise ArgumentError, "association names must be a Symbol" unless name.kind_of?(Symbol)
|
40
39
|
|
41
40
|
validate_options(options)
|
42
41
|
|
43
|
-
|
42
|
+
extension = define_extensions(model, name, &block)
|
43
|
+
options[:extend] = [*options[:extend], extension] if extension
|
44
|
+
|
45
|
+
scope = build_scope(scope)
|
44
46
|
|
45
47
|
ActiveRecord::Reflection.create(macro, name, scope, options, model)
|
46
48
|
end
|
47
49
|
|
48
|
-
def self.build_scope(scope
|
49
|
-
new_scope = scope
|
50
|
-
|
50
|
+
def self.build_scope(scope)
|
51
51
|
if scope && scope.arity == 0
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
if extension
|
56
|
-
new_scope = wrap_scope new_scope, extension
|
52
|
+
proc { instance_exec(&scope) }
|
53
|
+
else
|
54
|
+
scope
|
57
55
|
end
|
58
|
-
|
59
|
-
new_scope
|
60
|
-
end
|
61
|
-
|
62
|
-
def self.wrap_scope(scope, extension)
|
63
|
-
scope
|
64
56
|
end
|
65
57
|
|
66
58
|
def self.macro
|
@@ -136,5 +128,9 @@ module ActiveRecord::Associations::Builder # :nodoc:
|
|
136
128
|
name = reflection.name
|
137
129
|
model.before_destroy lambda { |o| o.association(name).handle_dependency }
|
138
130
|
end
|
131
|
+
|
132
|
+
private_class_method :build_scope, :macro, :valid_options, :validate_options, :define_extensions,
|
133
|
+
:define_callbacks, :define_accessors, :define_readers, :define_writers, :define_validations,
|
134
|
+
:valid_dependent_options, :check_dependent_options, :add_destroy_callbacks
|
139
135
|
end
|
140
136
|
end
|