Skip to content

Commit

Permalink
Destroy dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
vstabile committed May 29, 2018
1 parent d068aa4 commit cb7158f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
2 changes: 1 addition & 1 deletion app/models/plutus/account.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class Account < ActiveRecord::Base
has_many :amounts
has_many :credit_amounts, :extend => AmountsExtension, :class_name => 'Plutus::CreditAmount'
has_many :debit_amounts, :extend => AmountsExtension, :class_name => 'Plutus::DebitAmount'
has_many :entries, through: :amounts, source: :entry
has_many :entries, through: :amounts, source: :entry, :dependent => :destroy
has_many :credit_entries, :through => :credit_amounts, :source => :entry, :class_name => 'Plutus::Entry'
has_many :debit_entries, :through => :debit_amounts, :source => :entry, :class_name => 'Plutus::Entry'

Expand Down
12 changes: 8 additions & 4 deletions app/models/plutus/entry.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,14 @@ class Entry < ActiveRecord::Base
belongs_to :commercial_document, :polymorphic => true
end

has_many :credit_amounts, :extend => AmountsExtension, :class_name => 'Plutus::CreditAmount', :inverse_of => :entry
has_many :debit_amounts, :extend => AmountsExtension, :class_name => 'Plutus::DebitAmount', :inverse_of => :entry
has_many :credit_accounts, :through => :credit_amounts, :source => :account, :class_name => 'Plutus::Account'
has_many :debit_accounts, :through => :debit_amounts, :source => :account, :class_name => 'Plutus::Account'
has_many :credit_amounts, :extend => AmountsExtension, :class_name => 'Plutus::CreditAmount',
:inverse_of => :entry, :dependent => :destroy
has_many :debit_amounts, :extend => AmountsExtension, :class_name => 'Plutus::DebitAmount',
:inverse_of => :entry, :dependent => :destroy
has_many :credit_accounts, :through => :credit_amounts, :source => :account,
:class_name => 'Plutus::Account'
has_many :debit_accounts, :through => :debit_amounts, :source => :account,
:class_name => 'Plutus::Account'

validates_presence_of :description
validate :has_credit_amounts?
Expand Down

0 comments on commit cb7158f

Please sign in to comment.