module Sequel::Plugins::DelayAddAssociation

  1. lib/sequel/plugins/delay_add_association.rb

The delay_add_association plugin delays the adding of associated objects to a new (unsaved) object until after the new object is saved. By default, if you attempt to add associated objects to a new object, Sequel will raise an error, because you need to have a primary key before saving the objects.

When delaying the add of an associated object, the object will be immediately added to the cached association array. When saving the current object, it will also attempt to validate any associated objects, and if the associated objects are not valid, the current object will also be considered not valid.

Usage:

# Make all model subclass delay add_association for new objects
Sequel::Model.plugin :delay_add_association

# Make the Album class delay add_association for new objects
Album.plugin :delay_add_association

Methods

Public Class

  1. apply

Public Class methods

apply (mod)

Depend on the validate_associated plugin.

[show source]
# File lib/sequel/plugins/delay_add_association.rb, line 27
def self.apply(mod)
  mod.plugin :validate_associated
end