Module: Generalis::Transaction::Links

Defined in:
lib/generalis/transaction/links.rb

Instance Method Summary collapse

Instance Method Details

#has_many_linked(name, class_name: name.to_s.singularize.classify) ⇒ void

This method returns an undefined value.

Parameters:

  • name (Symbol)
  • class_name (String) (defaults to: name.to_s.singularize.classify)


20
21
22
23
24
25
26
# File 'lib/generalis/transaction/links.rb', line 20

def has_many_linked(name, class_name: name.to_s.singularize.classify) # rubocop:disable Naming/PredicateName
  has_many :"#{name}_links", -> { where(name: name) },
           class_name: 'Generalis::Link', dependent: :destroy,
           foreign_key: :transaction_id, inverse_of: :ledger_transaction

  has_many name, through: :"#{name}_links", source: :linkable, source_type: class_name
end

#has_one_linked(name, class_name: name.to_s.classify) ⇒ void

This method returns an undefined value.

Parameters:

  • name (Symbol)
  • class_name (String) (defaults to: name.to_s.classify)


9
10
11
12
13
14
15
# File 'lib/generalis/transaction/links.rb', line 9

def has_one_linked(name, class_name: name.to_s.classify) # rubocop:disable Naming/PredicateName
  has_one :"#{name}_link", -> { where(name: name) },
          class_name: 'Generalis::Link', dependent: :destroy,
          foreign_key: :transaction_id, inverse_of: :ledger_transaction

  has_one name, through: :"#{name}_link", source: :linkable, source_type: class_name
end