Skip to content

Commit

Permalink
Add has_one association to payment -> payment_method
Browse files Browse the repository at this point in the history
  • Loading branch information
Josephu committed Apr 25, 2013
1 parent a559814 commit 2637165
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
12 changes: 12 additions & 0 deletions lib/zuora/associations.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,18 @@ def has_many(klass_sym)
end
end

def has_one(klass_sym)
prefix = "Zuora::Objects::"
klass_name = prefix + klass_sym.to_s.classify

instance_eval do
define_method "#{klass_sym}" do
klass = klass_name.constantize
klass.where("Id = '#{self.send("#{klass_sym}_id")}'").try(:first)
end
end
end

def belongs_to(*args)
klass_sym = args.first.to_sym
options = args.extract_options!
Expand Down
1 change: 1 addition & 0 deletions lib/zuora/objects/payment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ module Zuora::Objects
class Payment < Base
belongs_to :account
belongs_to :invoice
has_one :payment_method

validates_presence_of :account_id, :amount, :effective_date, :status, :type

Expand Down

0 comments on commit 2637165

Please sign in to comment.