Module: IronAdmin::Concerns::Nestable::AssociationDsl

Defined in:
lib/iron_admin/concerns/nestable.rb

Overview

DSL methods for declaring has_many/has_one with nested options.

Instance Method Summary collapse

Instance Method Details

#has_many(name, nested: false, allow_destroy: true, position_field: nil, fields: nil, **options) ⇒ Object



14
15
16
17
18
19
20
21
# File 'lib/iron_admin/concerns/nestable.rb', line 14

def has_many(name, nested: false, allow_destroy: true, position_field: nil, fields: nil, **options)
  self.defined_associations = defined_associations.merge(
    name => {
      kind: :has_many, nested: nested, allow_destroy: allow_destroy,
      position_field: position_field&.to_sym, fields: fields&.map(&:to_sym), **options,
    }
  )
end

#has_one(name, nested: false, allow_destroy: true, fields: nil, **options) ⇒ Object



23
24
25
26
27
28
29
30
# File 'lib/iron_admin/concerns/nestable.rb', line 23

def has_one(name, nested: false, allow_destroy: true, fields: nil, **options)
  self.defined_associations = defined_associations.merge(
    name => {
      kind: :has_one, nested: nested, allow_destroy: allow_destroy,
      fields: fields&.map(&:to_sym), **options,
    }
  )
end