Added associations
This commit is contained in:
parent
dcae5f8784
commit
29a9af3cf0
3 changed files with 13 additions and 2 deletions
|
@ -10,4 +10,7 @@
|
|||
#
|
||||
|
||||
class Client < ActiveRecord::Base
|
||||
def transactions
|
||||
Transaction.where(origin: name)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -13,6 +13,10 @@
|
|||
#
|
||||
|
||||
class Transaction < ActiveRecord::Base
|
||||
belongs_to :debtor
|
||||
belongs_to :creditor
|
||||
belongs_to :debtor, class_name: 'User'
|
||||
belongs_to :creditor, class_name: 'User'
|
||||
|
||||
def client
|
||||
Client.find_by name: origin
|
||||
end
|
||||
end
|
||||
|
|
|
@ -12,4 +12,8 @@
|
|||
|
||||
class User < ActiveRecord::Base
|
||||
devise :timeoutable, :omniauthable, :omniauth_providers => [:zeuswpi]
|
||||
has_many :incoming_transactions,
|
||||
class_name: 'Transaction', foreign_key: 'creditor_id'
|
||||
has_many :outgoing_transactions,
|
||||
class_name: 'Transaction', foreign_key: 'debtor_id'
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue