Skip to content

Instantly share code, notes, and snippets.

@kalleth
Created August 5, 2013 20:56
Show Gist options
  • Save kalleth/7d4ae4e0f005ddf76ea3 to your computer and use it in GitHub Desktop.
Save kalleth/7d4ae4e0f005ddf76ea3 to your computer and use it in GitHub Desktop.
DataMapper 1.4 wtf
cbs_development=# \d payment_informations
Table "public.payment_informations"
Column | Type | Modifiers
--------------------------+-----------------------+-------------------------------------------------------------------
id | integer | not null default nextval('payment_informations_id_seq'::regclass)
payment_method | character varying(50) |
payment_amount | numeric(10,2) |
commission_by_percentage | boolean |
commission | numeric(10,2) |
paid | boolean |
booking_id | integer | not null
Indexes:
"payment_informations_pkey" PRIMARY KEY, btree (id)
"index_payment_informations_booking" btree (booking_id)
Foreign-key constraints:
"payment_informations_booking_fk" FOREIGN KEY (booking_id) REFERENCES bookings(id)
class PaymentInformation
include DataMapper::Resource
property :payment_method, String
property :payment_amount, Decimal, :precision => 10, :scale => 2
property :commission_by_percentage, Boolean #If true, commission is a %, else fixed fee.
property :commission, Decimal, :precision => 10, :scale => 2
property :paid, Boolean #Marked as true once this has been paid
belongs_to :booking
validates_presence_of :payment_method, :payment_amount
end
[17] pry(#<BookingsController>)> @booking.payment_information.valid?
=> true
[18] pry(#<BookingsController>)> @booking.payment_information.save
=> false
20] pry(#<BookingsController>)> @booking.payment_information.attributes
=> {:id=>nil,
:payment_method=>"COTN",
:payment_amount=>#<BigDecimal:7fa49d13aad0,'0.5E3',9(18)>,
:commission_by_percentage=>true,
:commission=>#<BigDecimal:7fa49d139b80,'0.7E1',9(18)>,
:paid=>nil,
:booking_id=>5}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment