activerecord 4.2.0.beta1 → 4.2.0.beta2

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.

Files changed (53) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +137 -38
  3. data/lib/active_record/associations.rb +78 -13
  4. data/lib/active_record/associations/association_scope.rb +53 -40
  5. data/lib/active_record/associations/collection_association.rb +1 -1
  6. data/lib/active_record/associations/collection_proxy.rb +4 -4
  7. data/lib/active_record/associations/has_many_through_association.rb +6 -6
  8. data/lib/active_record/associations/join_dependency/join_association.rb +1 -1
  9. data/lib/active_record/associations/preloader.rb +32 -23
  10. data/lib/active_record/associations/singular_association.rb +1 -1
  11. data/lib/active_record/associations/through_association.rb +5 -1
  12. data/lib/active_record/attribute_methods.rb +7 -7
  13. data/lib/active_record/attribute_methods/dirty.rb +20 -9
  14. data/lib/active_record/attribute_methods/query.rb +1 -1
  15. data/lib/active_record/attribute_methods/read.rb +1 -3
  16. data/lib/active_record/attribute_methods/serialization.rb +3 -4
  17. data/lib/active_record/attribute_methods/time_zone_conversion.rb +2 -0
  18. data/lib/active_record/autosave_association.rb +3 -3
  19. data/lib/active_record/connection_adapters/abstract/connection_pool.rb +1 -1
  20. data/lib/active_record/connection_adapters/abstract/database_statements.rb +5 -0
  21. data/lib/active_record/connection_adapters/abstract/schema_creation.rb +2 -0
  22. data/lib/active_record/connection_adapters/abstract/schema_definitions.rb +5 -8
  23. data/lib/active_record/connection_adapters/abstract/schema_dumper.rb +8 -4
  24. data/lib/active_record/connection_adapters/abstract/transaction.rb +11 -5
  25. data/lib/active_record/connection_adapters/abstract_adapter.rb +7 -1
  26. data/lib/active_record/connection_adapters/abstract_mysql_adapter.rb +23 -15
  27. data/lib/active_record/connection_adapters/mysql2_adapter.rb +1 -1
  28. data/lib/active_record/connection_adapters/mysql_adapter.rb +1 -1
  29. data/lib/active_record/connection_adapters/postgresql/oid/range.rb +4 -4
  30. data/lib/active_record/connection_adapters/postgresql/oid/uuid.rb +2 -0
  31. data/lib/active_record/connection_adapters/postgresql/schema_definitions.rb +3 -5
  32. data/lib/active_record/connection_adapters/postgresql/schema_statements.rb +8 -6
  33. data/lib/active_record/connection_adapters/postgresql_adapter.rb +9 -6
  34. data/lib/active_record/connection_adapters/sqlite3_adapter.rb +6 -5
  35. data/lib/active_record/core.rb +11 -3
  36. data/lib/active_record/counter_cache.rb +1 -1
  37. data/lib/active_record/fixtures.rb +15 -8
  38. data/lib/active_record/gem_version.rb +2 -2
  39. data/lib/active_record/migration.rb +8 -12
  40. data/lib/active_record/reflection.rb +20 -18
  41. data/lib/active_record/relation/calculations.rb +7 -7
  42. data/lib/active_record/relation/finder_methods.rb +10 -9
  43. data/lib/active_record/relation/predicate_builder.rb +2 -2
  44. data/lib/active_record/relation/predicate_builder/array_handler.rb +12 -4
  45. data/lib/active_record/relation/query_methods.rb +8 -12
  46. data/lib/active_record/schema_dumper.rb +20 -28
  47. data/lib/active_record/tasks/database_tasks.rb +9 -5
  48. data/lib/active_record/transactions.rb +9 -9
  49. data/lib/active_record/type.rb +1 -0
  50. data/lib/active_record/type/binary.rb +10 -0
  51. data/lib/active_record/type/decorator.rb +14 -0
  52. data/lib/active_record/type/serialized.rb +8 -3
  53. metadata +7 -6
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 57b65593b6cdbb77e81c448af2b0e2c0f0776680
4
- data.tar.gz: cea842a9261ae06b3a9ee0c5d1e276743c496457
3
+ metadata.gz: 211710d5cc673b4cc8739c6192094e48c7d8cea7
4
+ data.tar.gz: d5ed042f529bb6cea7663f61dbef6220803f1bdb
5
5
  SHA512:
6
- metadata.gz: a95a9d12073d982417b4f08f02ac3492545e5096a3bea0b9400c933738709010f763a0961914bf0fa135013a4d315eb50efb38091d7cacf90f71c6c8bf1699b4
7
- data.tar.gz: 345909347c2549c3be866f3cb335e561acafde1a26682705dd90d0d8022875a3fe19871e1402a43717dc28b2405a2450d224f39620ae7dd2a928bf76b0017af3
6
+ metadata.gz: 56a7041e9c7234e5be445391024eebd82ad24addd37a9d33bb44c76ed34515be23a3387e44065d287bbf100d79f0e336d479bb72d06960891b0cec044a599985
7
+ data.tar.gz: f2c89b0e109a6e52a6e8be18b2fd060abc8733348bdb65182fa11b3e0d924bcb400e34855c7419e6900071eed9111e5da56799f6714e1866845a81f8cb9d1278
@@ -1,17 +1,123 @@
1
- * Fixed the `Relation#exists?` to work with polymorphic associations.
1
+ * Honor overridden `rack.test` in Rack environment for the connection
2
+ management middlware.
3
+
4
+ *Simon Eskildsen*
5
+
6
+ * Add a truncate method to the connection.
7
+
8
+ *Aaron Patterson*
9
+
10
+ * Don't autosave unchanged has_one through records.
11
+
12
+ *Alan Kennedy*, *Steve Parrington*
13
+
14
+ * Do not dump foreign keys for ignored tables.
15
+
16
+ *Yves Senn*
17
+
18
+ * PostgreSQL adapter correctly dumps foreign keys targeting tables
19
+ outside the schema search path.
20
+
21
+ Fixes #16907.
22
+
23
+ *Matthew Draper*, *Yves Senn*
24
+
25
+ * When a thread is killed, rollback the active transaction, instead of
26
+ committing it during the stack unwind. Previously, we could commit half-
27
+ completed work. This fix only works for Ruby 2.0+; on 1.9, we can't
28
+ distinguish a thread kill from an ordinary non-local (block) return, so must
29
+ default to committing.
30
+
31
+ *Chris Hanks*
32
+
33
+ * A `NullRelation` should represent nothing. This fixes a bug where
34
+ `Comment.where(post_id: Post.none)` returned a non-empty result.
35
+
36
+ Fixes #15176.
37
+
38
+ *Matthew Draper*, *Yves Senn*
39
+
40
+ * Include default column limits in schema.rb. Allows defaults to be changed
41
+ in the future without affecting old migrations that assumed old defaults.
42
+
43
+ *Jeremy Kemper*
44
+
45
+ * MySQL: schema.rb now includes TEXT and BLOB column limits.
46
+
47
+ *Jeremy Kemper*
48
+
49
+ * MySQL: correct LONGTEXT and LONGBLOB limits from 2GB to their true 4GB.
50
+
51
+ *Jeremy Kemper*
52
+
53
+ * SQLite3Adapter now checks for views in `table_exists?`. Fixes #14041.
54
+
55
+ *Girish Sonawane*
56
+
57
+ * Introduce `connection.supports_views?` to check whether the current adapter
58
+ has support for SQL views. Connection adapters should define this method.
59
+
60
+ *Yves Senn*
61
+
62
+ * Allow included modules to override association methods.
63
+
64
+ Fixes #16684.
65
+
66
+ *Yves Senn*
67
+
68
+ * Schema loading rake tasks (like `db:schema:load` and `db:setup`) maintain
69
+ the database connection to the current environment.
70
+
71
+ Fixes #16757.
72
+
73
+ *Joshua Cody*, *Yves Senn*
74
+
75
+ * MySQL: set the connection collation along with the charset.
76
+
77
+ Sets the connection collation to the database collation configured in
78
+ database.yml. Otherwise, `SET NAMES utf8mb4` will use the default
79
+ collation for that charset (utf8mb4_general_ci) when you may have chosen
80
+ a different collation, like utf8mb4_unicode_ci.
81
+
82
+ This only applies to literal string comparisons, not column values, so it
83
+ is unlikely to affect you.
84
+
85
+ *Jeremy Kemper*
86
+
87
+ * `default_sequence_name` from the PostgreSQL adapter returns a `String`.
88
+
89
+ *Yves Senn*
90
+
91
+ * Fixed a regression where whitespaces were stripped from DISTINCT queries in
92
+ PostgreSQL.
93
+
94
+ *Agis Anastasopoulos*
95
+
96
+ Fixes #16623.
97
+
98
+ * Fix has_many :through relation merging failing when dynamic conditions are
99
+ passed as a lambda with an arity of one.
100
+
101
+ Fixes #16128.
102
+
103
+ *Agis Anastasopoulos*
104
+
105
+ * Fixed `Relation#exists?` to work with polymorphic associations.
2
106
 
3
107
  Fixes #15821.
4
108
 
5
109
  *Kassio Borges*
6
110
 
7
- * Currently, Active Record will rescue any errors raised within
8
- after_rollback/after_create callbacks and print them to the logs. Next versions of rails
9
- will not rescue those errors anymore, and just bubble them up, as the other callbacks.
111
+ * Currently, Active Record rescues any errors raised within
112
+ `after_rollback`/`after_create` callbacks and prints them to the logs.
113
+ Future versions of Rails will not rescue these errors anymore and
114
+ just bubble them up like the other callbacks.
115
+
116
+ This commit adds an opt-in flag to enable not rescuing the errors.
10
117
 
11
- This adds a opt-in flag to enable that behaviour, of not rescuing the errors.
12
118
  Example:
13
119
 
14
- # For not swallow errors in after_commit/after_rollback callbacks.
120
+ # Do not swallow errors in after_commit/after_rollback callbacks.
15
121
  config.active_record.raise_in_transactional_callbacks = true
16
122
 
17
123
  Fixes #13460.
@@ -31,9 +137,9 @@
31
137
 
32
138
  *Sean Griffin*
33
139
 
34
- * Fix regression on after_commit that didnt fire when having nested transactions.
140
+ * Fix regression on `after_commit` that did not fire with nested transactions.
35
141
 
36
- Fixes #16425
142
+ Fixes #16425.
37
143
 
38
144
  *arthurnn*
39
145
 
@@ -67,9 +173,9 @@
67
173
 
68
174
  * Define `id_was` to get the previous value of the primary key.
69
175
 
70
- Currently when we call id_was and we have a custom primary key name
176
+ Currently when we call `id_was` and we have a custom primary key name,
71
177
  Active Record will return the current value of the primary key. This
72
- make impossible to correctly do an update operation if you change the
178
+ makes it impossible to correctly do an update operation if you change the
73
179
  id.
74
180
 
75
181
  Fixes #16413.
@@ -101,7 +207,7 @@
101
207
 
102
208
  *Eileen M. Uchtitelle*, *Aaron Patterson*
103
209
 
104
- * No verbose backtrace by db:drop when database does not exist.
210
+ * No verbose backtrace by `db:drop` when database does not exist.
105
211
 
106
212
  Fixes #16295.
107
213
 
@@ -146,7 +252,7 @@
146
252
 
147
253
  *Stefan Kanev*
148
254
 
149
- * Dont swallow errors on compute_type when having a bad alias_method on
255
+ * Do not swallow errors on `compute_type` when having a bad `alias_method` on
150
256
  a class.
151
257
 
152
258
  *arthurnn*
@@ -229,7 +335,7 @@
229
335
 
230
336
  *Eileen M. Uchitelle, Aaron Patterson*
231
337
 
232
- * Avoid type casting boolean and ActiveSupport::Duration values to numeric
338
+ * Avoid type casting boolean and `ActiveSupport::Duration` values to numeric
233
339
  values for string columns. Otherwise, in some database, the string column
234
340
  values will be coerced to a numeric allowing false or 0.seconds match any
235
341
  string starting with a non-digit.
@@ -260,8 +366,8 @@
260
366
 
261
367
  *Abdelkader Boudih*
262
368
 
263
- * Move 'dependent: :destroy' handling for 'belongs_to'
264
- from 'before_destroy' to 'after_destroy' callback chain
369
+ * Move 'dependent: :destroy' handling for `belongs_to`
370
+ from `before_destroy` to `after_destroy` callback chain
265
371
 
266
372
  Fixes #12380.
267
373
 
@@ -269,8 +375,9 @@
269
375
 
270
376
  * Detect in-place modifications on String attributes.
271
377
 
272
- Before this change user have to mark the attribute as changed to it be persisted
273
- in the database. Now it is not required anymore.
378
+ Before this change, an attribute modified in-place had to be marked as
379
+ changed in order for it to be persisted in the database. Now it is no longer
380
+ required.
274
381
 
275
382
  Before:
276
383
 
@@ -350,14 +457,6 @@
350
457
 
351
458
  *Sean Griffin*
352
459
 
353
- * `has_many :through` associations will no longer save the through record
354
- twice when added in an `after_create` callback defined before the
355
- associations.
356
-
357
- Fixes #3798.
358
-
359
- *Sean Griffin*
360
-
361
460
  * Detect in-place modifications of PG array types
362
461
 
363
462
  *Sean Griffin*
@@ -390,7 +489,7 @@
390
489
 
391
490
  *Sean Griffin*
392
491
 
393
- * Pluck now works when selecting columns from different tables with the same
492
+ * `Pluck` now works when selecting columns from different tables with the same
394
493
  name.
395
494
 
396
495
  Fixes #15649.
@@ -457,7 +556,7 @@
457
556
 
458
557
  *Sean Griffin*
459
558
 
460
- * Implemented ActiveRecord::Base#pretty_print to work with PP.
559
+ * Implemented `ActiveRecord::Base#pretty_print` to work with PP.
461
560
 
462
561
  *Ethan*
463
562
 
@@ -498,16 +597,16 @@
498
597
 
499
598
  *Arun Agrawal*
500
599
 
501
- * Fix redefine a has_and_belongs_to_many inside inherited class
502
- Fixing regression case, where redefining the same has_an_belongs_to_many
600
+ * Fix redefine a `has_and_belongs_to_many` inside inherited class
601
+ Fixing regression case, where redefining the same `has_and_belongs_to_many`
503
602
  definition into a subclass would raise.
504
603
 
505
604
  Fixes #14983.
506
605
 
507
606
  *arthurnn*
508
607
 
509
- * Fix has_and_belongs_to_many public reflection.
510
- When defining a has_and_belongs_to_many, internally we convert that to two has_many.
608
+ * Fix `has_and_belongs_to_many` public reflection.
609
+ When defining a `has_and_belongs_to_many`, internally we convert that to two has_many.
511
610
  But as `reflections` is a public API, people expect to see the right macro.
512
611
 
513
612
  Fixes #14682.
@@ -544,7 +643,7 @@
544
643
 
545
644
  *Brock Trappitt*
546
645
 
547
- * Fixed the inferred table name of a has_and_belongs_to_many auxiliar
646
+ * Fixed the inferred table name of a `has_and_belongs_to_many` auxiliar
548
647
  table inside a schema.
549
648
 
550
649
  Fixes #14824.
@@ -588,7 +687,7 @@
588
687
 
589
688
  *Aaron Nelson*
590
689
 
591
- * Fix how to calculate associated class name when using namespaced has_and_belongs_to_many
690
+ * Fix how to calculate associated class name when using namespaced `has_and_belongs_to_many`
592
691
  association.
593
692
 
594
693
  Fixes #14709.
@@ -658,7 +757,7 @@
658
757
 
659
758
  * Fixed has_and_belongs_to_many's CollectionAssociation size calculation.
660
759
 
661
- has_and_belongs_to_many should fall back to using the normal CollectionAssociation's
760
+ `has_and_belongs_to_many` should fall back to using the normal CollectionAssociation's
662
761
  size calculation if the collection is not cached or loaded.
663
762
 
664
763
  Fixes #14913, #14914.
@@ -718,7 +817,7 @@
718
817
 
719
818
  *Timur Alperovich*
720
819
 
721
- * Give ActiveRecord::PredicateBuilder private methods the privacy they deserve.
820
+ * Give `ActiveRecord::PredicateBuilder` private methods the privacy they deserve.
722
821
 
723
822
  *Hector Satre*
724
823
 
@@ -774,7 +873,7 @@
774
873
 
775
874
  *Kuldeep Aggarwal*
776
875
 
777
- * Fixed has_many association to make it support irregular inflections.
876
+ * Fixed `has_many` association to make it support irregular inflections.
778
877
 
779
878
  Fixes #8928.
780
879
 
@@ -888,7 +987,7 @@
888
987
 
889
988
  * `to_sql` on an association now matches the query that is actually executed, where it
890
989
  could previously have incorrectly accrued additional conditions (e.g. as a result of
891
- a previous query). CollectionProxy now always defers to the association scope's
990
+ a previous query). `CollectionProxy` now always defers to the association scope's
892
991
  `arel` method so the (incorrect) inherited one should be entirely concealed.
893
992
 
894
993
  Fixes #14003.
@@ -1119,7 +1218,7 @@
1119
1218
 
1120
1219
  The current solution of incrementing the beginning is not correct and is now
1121
1220
  deprecated. For subtypes where we don't know how to increment (e.g. `#succ`
1122
- is not defined) it will raise an ArgumentException for ranges with excluding
1221
+ is not defined) it will raise an `ArgumentException` for ranges with excluding
1123
1222
  beginnings.
1124
1223
 
1125
1224
  *Yves Senn*
@@ -447,9 +447,11 @@ module ActiveRecord
447
447
  #
448
448
  # Possible callbacks are: +before_add+, +after_add+, +before_remove+ and +after_remove+.
449
449
  #
450
- # Should any of the +before_add+ callbacks throw an exception, the object does not get
451
- # added to the collection. Same with the +before_remove+ callbacks; if an exception is
452
- # thrown the object doesn't get removed.
450
+ # If any of the +before_add+ callbacks throw an exception, the object will not be
451
+ # added to the collection.
452
+ #
453
+ # Similarly, if any of the +before_remove+ callbacks throw an exception, the object
454
+ # will not be removed from the collection.
453
455
  #
454
456
  # == Association extensions
455
457
  #
@@ -647,7 +649,7 @@ module ActiveRecord
647
649
  # belongs_to :commenter
648
650
  # end
649
651
  #
650
- # When using nested association, you will not be able to modify the association because there
652
+ # When using a nested association, you will not be able to modify the association because there
651
653
  # is not enough information to know what modification to make. For example, if you tried to
652
654
  # add a <tt>Commenter</tt> in the example above, there would be no way to tell how to set up the
653
655
  # intermediate <tt>Post</tt> and <tt>Comment</tt> objects.
@@ -717,7 +719,7 @@ module ActiveRecord
717
719
  # == Eager loading of associations
718
720
  #
719
721
  # Eager loading is a way to find objects of a certain class and a number of named associations.
720
- # This is one of the easiest ways of to prevent the dreaded N+1 problem in which fetching 100
722
+ # It is one of the easiest ways to prevent the dreaded N+1 problem in which fetching 100
721
723
  # posts that each need to display their author triggers 101 database queries. Through the
722
724
  # use of eager loading, the number of queries will be reduced from 101 to 2.
723
725
  #
@@ -749,16 +751,16 @@ module ActiveRecord
749
751
  # Post.includes(:author, :comments).each do |post|
750
752
  #
751
753
  # This will load all comments with a single query. This reduces the total number of queries
752
- # to 3. More generally the number of queries will be 1 plus the number of associations
754
+ # to 3. In general, the number of queries will be 1 plus the number of associations
753
755
  # named (except if some of the associations are polymorphic +belongs_to+ - see below).
754
756
  #
755
757
  # To include a deep hierarchy of associations, use a hash:
756
758
  #
757
- # Post.includes(:author, {comments: {author: :gravatar}}).each do |post|
759
+ # Post.includes(:author, { comments: { author: :gravatar } }).each do |post|
758
760
  #
759
- # That'll grab not only all the comments but all their authors and gravatar pictures.
760
- # You can mix and match symbols, arrays and hashes in any combination to describe the
761
- # associations you want to load.
761
+ # The above code will load all the comments and all of their associated
762
+ # authors and gravatars. You can mix and match any combination of symbols,
763
+ # arrays, and hashes to retrieve the associations you want to load.
762
764
  #
763
765
  # All of this power shouldn't fool you into thinking that you can pull out huge amounts
764
766
  # of data with no performance penalty just because you've reduced the number of queries.
@@ -767,8 +769,8 @@ module ActiveRecord
767
769
  # cut down on the number of queries in a situation as the one described above.
768
770
  #
769
771
  # Since only one table is loaded at a time, conditions or orders cannot reference tables
770
- # other than the main one. If this is the case Active Record falls back to the previously
771
- # used LEFT OUTER JOIN based strategy. For example
772
+ # other than the main one. If this is the case, Active Record falls back to the previously
773
+ # used LEFT OUTER JOIN based strategy. For example:
772
774
  #
773
775
  # Post.includes([:author, :comments]).where(['comments.approved = ?', true])
774
776
  #
@@ -1133,6 +1135,31 @@ module ActiveRecord
1133
1135
  # * <tt>Firm#clients.create!</tt> (similar to <tt>c = Client.new("firm_id" => id); c.save!</tt>)
1134
1136
  # The declaration can also include an +options+ hash to specialize the behavior of the association.
1135
1137
  #
1138
+ # === Scopes
1139
+ #
1140
+ # You can pass a second argument +scope+ as a callable (i.e. proc or
1141
+ # lambda) to retrieve a specific set of records or customize the generated
1142
+ # query when you access the associated collection.
1143
+ #
1144
+ # Scope examples:
1145
+ # has_many :comments, -> { where(author_id: 1) }
1146
+ # has_many :employees, -> { joins(:address) }
1147
+ # has_many :posts, ->(post) { where("max_post_length > ?", post.length) }
1148
+ #
1149
+ # === Extensions
1150
+ #
1151
+ # The +extension+ argument allows you to pass a block into a has_many
1152
+ # association. This is useful for adding new finders, creators and other
1153
+ # factory-type methods to be used as part of the association.
1154
+ #
1155
+ # Extension examples:
1156
+ # has_many :employees do
1157
+ # def find_or_create_by_name(name)
1158
+ # first_name, last_name = name.split(" ", 2)
1159
+ # find_or_create_by(first_name: first_name, last_name: last_name)
1160
+ # end
1161
+ # end
1162
+ #
1136
1163
  # === Options
1137
1164
  # [:class_name]
1138
1165
  # Specify the class name of the association. Use it only if that name can't be inferred
@@ -1144,7 +1171,7 @@ module ActiveRecord
1144
1171
  # of this class in lower-case and "_id" suffixed. So a Person class that makes a +has_many+
1145
1172
  # association will use "person_id" as the default <tt>:foreign_key</tt>.
1146
1173
  # [:primary_key]
1147
- # Specify the method that returns the primary key used for the association. By default this is +id+.
1174
+ # Specify the name of the column to use as the primary key for the association. By default this is +id+.
1148
1175
  # [:dependent]
1149
1176
  # Controls what happens to the associated objects when
1150
1177
  # their owner is destroyed. Note that these are implemented as
@@ -1257,6 +1284,17 @@ module ActiveRecord
1257
1284
  # * <tt>Account#create_beneficiary</tt> (similar to <tt>b = Beneficiary.new("account_id" => id); b.save; b</tt>)
1258
1285
  # * <tt>Account#create_beneficiary!</tt> (similar to <tt>b = Beneficiary.new("account_id" => id); b.save!; b</tt>)
1259
1286
  #
1287
+ # === Scopes
1288
+ #
1289
+ # You can pass a second argument +scope+ as a callable (i.e. proc or
1290
+ # lambda) to retrieve a specific record or customize the generated query
1291
+ # when you access the associated object.
1292
+ #
1293
+ # Scope examples:
1294
+ # has_one :author, -> { where(comment_id: 1) }
1295
+ # has_one :employer, -> { joins(:company) }
1296
+ # has_one :dob, ->(dob) { where("Date.new(2000, 01, 01) > ?", dob) }
1297
+ #
1260
1298
  # === Options
1261
1299
  #
1262
1300
  # The declaration can also include an +options+ hash to specialize the behavior of the association.
@@ -1554,6 +1592,33 @@ module ActiveRecord
1554
1592
  # * <tt>Developer#projects.create</tt> (similar to <tt>c = Project.new("developer_id" => id); c.save; c</tt>)
1555
1593
  # The declaration may include an +options+ hash to specialize the behavior of the association.
1556
1594
  #
1595
+ # === Scopes
1596
+ #
1597
+ # You can pass a second argument +scope+ as a callable (i.e. proc or
1598
+ # lambda) to retrieve a specific set of records or customize the generated
1599
+ # query when you access the associated collection.
1600
+ #
1601
+ # Scope examples:
1602
+ # has_and_belongs_to_many :projects, -> { includes :milestones, :manager }
1603
+ # has_and_belongs_to_many :categories, ->(category) {
1604
+ # where("default_category = ?", category.name)
1605
+ # }
1606
+ #
1607
+ # === Extensions
1608
+ #
1609
+ # The +extension+ argument allows you to pass a block into a
1610
+ # has_and_belongs_to_many association. This is useful for adding new
1611
+ # finders, creators and other factory-type methods to be used as part of
1612
+ # the association.
1613
+ #
1614
+ # Extension examples:
1615
+ # has_and_belongs_to_many :contractors do
1616
+ # def find_or_create_by_name(name)
1617
+ # first_name, last_name = name.split(" ", 2)
1618
+ # find_or_create_by(first_name: first_name, last_name: last_name)
1619
+ # end
1620
+ # end
1621
+ #
1557
1622
  # === Options
1558
1623
  #
1559
1624
  # [:class_name]