1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
|
= New Features
* A detect_unnecessary_association_options plugin has been added,
which warns or raises for unnecessary association options. For
example, if you have an association such as:
Album.many_to_one :artist, class: :Artist, key: :artist_id
The plugin can inform you that the :class and :key options are
unnecessary, since they are the same as Sequel's defaults for
the options. That allows you to remove the unnecessary options:
Album.many_to_one :artist
The following unnecessary options are detected:
* :class (all associations)
* :key and :primary_key (associations without join tables)
* :join_table, :left_key, :right_key, :left_primary_key,
:right_primary_key (single join table associations)
* :left_primary_key, :right_primary_key (*_through_many
associations)
To use the plugin, generally you would load it into the base model
class before loading subclasses:
Sequel::Model.plugin :detect_unnecessary_association_options
After loading subclasses, you would call the
detect_unnecessary_association_options method on the subclasses.
If you are using the subclasses plugin, this can be done via:
Sequel::Model.descendants.each(&:detect_unnecessary_association_options)
Detection also happens implicitly when finalizing associations,
so the following will also work with the subclasses plugin:
Sequel::Model.freeze_descendants
By default, the plugin warns for unnecessary association options.
To have it raise an error instead:
Sequel::Model.plugin :detect_unnecessary_association_options, action: :raise
|