Added associations

This commit is contained in:
Ilion Beyst 2015-09-08 12:11:48 +02:00
parent dcae5f8784
commit 29a9af3cf0
3 changed files with 13 additions and 2 deletions

View file

@ -10,4 +10,7 @@
# #
class Client < ActiveRecord::Base class Client < ActiveRecord::Base
def transactions
Transaction.where(origin: name)
end
end end

View file

@ -13,6 +13,10 @@
# #
class Transaction < ActiveRecord::Base class Transaction < ActiveRecord::Base
belongs_to :debtor belongs_to :debtor, class_name: 'User'
belongs_to :creditor belongs_to :creditor, class_name: 'User'
def client
Client.find_by name: origin
end
end end

View file

@ -12,4 +12,8 @@
class User < ActiveRecord::Base class User < ActiveRecord::Base
devise :timeoutable, :omniauthable, :omniauth_providers => [:zeuswpi] 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 end