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 7db1168
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
2 changes: 1 addition & 1 deletion app/models/plutus/account.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ module Plutus
class Account < ActiveRecord::Base
class_attribute :normal_credit_balance

has_many :amounts
has_many :amounts, :dependent => :destroy
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
Expand Down
2 changes: 1 addition & 1 deletion app/models/plutus/amount.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ module Plutus
#
# @author Michael Bulat
class Amount < ActiveRecord::Base
belongs_to :entry, :class_name => 'Plutus::Entry'
belongs_to :entry, :class_name => 'Plutus::Entry', :dependent => :destroy
belongs_to :account, :class_name => 'Plutus::Account'

validates_presence_of :type, :amount, :entry, :account
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 7db1168

Please sign in to comment.