Skip to content

Instantly share code, notes, and snippets.

@pathsny
Forked from snusnu/payment and user.rb
Created April 27, 2010 17:30
Show Gist options
  • Save pathsny/381032 to your computer and use it in GitHub Desktop.
Save pathsny/381032 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
has n, :payments_as_payer, Payment, :child_key => [:payer_id]
has n, :payments_as_payee, Payment, :child_key => [:payee_id]
has n, :payees, User, :through => :payments_as_payer, :via => :payee_id
has n, :payers, User, :through => :payments_as_payee, :via => :payer_id
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment