-
-
Save kalleth/7d4ae4e0f005ddf76ea3 to your computer and use it in GitHub Desktop.
DataMapper 1.4 wtf
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[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