Skip to content

Instantly share code, notes, and snippets.

@joegaudet
Last active December 15, 2019 18:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joegaudet/c574691b8f9da5d70735337c74c90ef7 to your computer and use it in GitHub Desktop.
Save joegaudet/c574691b8f9da5d70735337c74c90ef7 to your computer and use it in GitHub Desktop.
Crazy Pills
# == Schema Information
#
# Table name: group_order_members
#
# id :integer not null, primary key
# name :string
# email :string
class GroupOrderMember < ApplicationRecord
include Accounting::Interfaces::Invoiceable
end
# == Schema Information
#
# Table name: accounting_ledger_items
#
# id :integer not null, primary key
# sender_type :string
# sender_id :integer
# recipient_type :string
# recipient_id :integer
# type :string
# issue_date :datetime
# currency :string(3) not null
# total_amount :decimal(20, 4)
# tax_amount :decimal(20, 4)
# status :string(20) not null
# identifier :string(50)
# description :string
# period_start :datetime
# period_end :datetime
# uuid :uuid
# due_date :datetime
# created_at :datetime not null
# updated_at :datetime not null
# invoiceable_type :string
# invoiceable_id :integer
# xero_id :uuid
#
class Accounting::Invoice < Accounting::LedgerItem
belongs_to :invoiceable, polymorphic: true
end
module Accounting
module Interfaces
module Invoiceable
extend ActiveSupport::Concern
included do
has_one :invoice, class_name: 'Accounting::Invoice', as: :invoiceable
end
end
end
end
[3] pry(main)> GroupOrderMember.last.invoice
GroupOrderMember Load (0.7ms) SELECT "group_order_members".* FROM "group_order_members" WHERE "group_order_members"."deleted_at" IS NULL ORDER BY "group_order_members"."id" DESC LIMIT 1
Accounting::Invoice Load (0.6ms) SELECT "accounting_ledger_items".* FROM "accounting_ledger_items" WHERE "accounting_ledger_items"."type" IN ('Accounting::Invoice') AND 1=0 AND 1=0 LIMIT 1
=> nil
[4] pry(main)> Accounting::Invoice.last.invoiceable
Accounting::Invoice Load (0.6ms) SELECT "accounting_ledger_items".* FROM "accounting_ledger_items" WHERE "accounting_ledger_items"."type" IN ('Accounting::Invoice') ORDER BY "accounting_ledger_items"."id" DESC LIMIT 1
Accounting::LineItem Load (0.5ms) SELECT "accounting_line_items".* FROM "accounting_line_items" WHERE "accounting_line_items"."ledger_item_id" = 10
GroupOrderMember Load (0.6ms) SELECT "group_order_members".* FROM "group_order_members" WHERE "group_order_members"."deleted_at" IS NULL AND "group_order_members"."id" = 6 LIMIT 1
=> #<GroupOrderMember:0x00007ffaa6468dd8
id: 6,
name: "asdf asdf",
user_id: nil,
order_id: 219,
created_at: Sat, 14 Dec 2019 17:53:14 UTC +00:00,
updated_at: Sat, 14 Dec 2019 17:53:21 UTC +00:00,
email: "asf@asdf.com",
legacy_phone_number: nil,
deleted_at: nil,
department: "test",
stripe_charge_token: nil,
stripe_charge_id: nil,
terms_accepted_at: nil,
notify_by_email_on_delivery: false,
notify_by_sms_on_delivery: false,
notification_preferences: {"sms_reminder"=>nil, "email_reminder"=>nil, "sms_on_delivery"=>nil, "email_on_delivery"=>nil, "sms_reminder_one_hour"=>nil, "email_reminder_one_hour"=>nil},
phone_number: nil,
number_of_people: nil,
custom_fields: {}>
[5] pry(main)>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment