module Itemable::ActsAsItemable::HasOneItem::ClassMethods

Public Instance Methods

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