module Itemable::ActsAsItemable::HasManyItems::ClassMethods

Public Instance Methods

has_many_items(association_name, options={}) click to toggle source
# File lib/itemable/acts_as_itemable.rb, line 37
def has_many_items(association_name, options={})
  default_options = {
    through: :item_children,
    source: :child,
    source_type: association_name.to_s.classify
  }.merge(options.symbolize_keys)
  if default_options[:dependent] == :destroy
    before_destroy prepend: true do
      send(association_name).each do |rec|
        rec.destroy
      end
    end
  end
  has_many association_name, default_options
end