Skip to content

Instantly share code, notes, and snippets.

@snusnu
Forked from myobie/payment and user.rb
Created April 27, 2010 17:21
Show Gist options
  • Save snusnu/381022 to your computer and use it in GitHub Desktop.
Save snusnu/381022 to your computer and use it in GitHub Desktop.
class Payment
include DataMapper::Resource
property :id, Serial
belongs_to :payee, 'User'
belongs_to :payer, 'User'
end
class User
include DataMapper::Resource
property :id, Serial
has n, :payments, 'Payment', :child_key => [:payer_id]
has n, :receivings, 'Payment', :child_key => [:payee_id]
has n, :payees, self, :through => :receivings, :via => :payee
has n, :payers, self, :through => :payments, :via => :payer
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment