Module: Sequel::Plugins::DeprecatedAssociations

Defined in:
lib/sequel/plugins/deprecated_associations.rb

Overview

The deprecated_associations plugin adds support for deprecating associations. Attempts to use association methods and access association metadata for deprecated associations results in a warning.

Album.plugin :deprecated_associations
Album.many_to_one :artist, deprecated: true
album = Album[1]

# Warnings for all of the following calls
album.artist
album.artist_dataset
album.artist = Artist[2]
Album.association_reflection(:artist)
Album.eager(:artist)
Album.eager_graph(:artist)
Album.where(artist: Artist[1]).all

By default, the plugin issues a single warning per association method or association reflection. See DeprecatedAssociations.configure for options to make deprecated association issue warnings for every access, to include backtraces in warnings, or to raise an exception instead of warning.

Note that Model.association_reflections and Model.all_association_reflections will include deprecated associations, and accessing the metadata for deprecated associations through these interfaces not issue warnings.

Usage:

# Make all models support deprecated associations
# (called before loading subclasses)
Sequel::Model.plugin :deprecated_associations

# Make Album class support deprecated associations
Album.plugin :deprecated_associations

Defined Under Namespace

Modules: ClassMethods Classes: Access

Class Method Summary collapse

Class Method Details

.configure(model, opts = OPTS) ⇒ Object

Configure the deprecated associations plugin. Options:

backtrace: Print backtrace with warning deduplicate: Set to false to emit warnings for every

deprecated association method call/access
(when not caching associations, this is always false)

raise: Raise Sequel::Plugin::DeprecatedAssociations::Access

instead of warning


56
57
58
59
60
# File 'lib/sequel/plugins/deprecated_associations.rb', line 56

def self.configure(model, opts = OPTS)
  model.instance_exec do
    (@deprecated_associations_config ||= {}).merge!(opts)
  end
end