Class: EdiDocument

Inherits:
ApplicationRecord show all
Defined in:
app/models/edi_document.rb

Overview

== Schema Information

Table name: edi_documents
Database name: primary

id :integer not null, primary key
note :string
resource_type :string
created_at :datetime not null
updated_at :datetime not null
amazon_variation_id :integer
catalog_item_id :integer
edi_communication_log_id :integer not null
invoice_id :integer
item_id :integer
order_id :integer
receipt_id :integer
resource_id :integer

Indexes

idx_unique_edi_documents (resource_type,resource_id,edi_communication_log_id) UNIQUE
index_edi_documents_on_amazon_variation_id (amazon_variation_id) WHERE (amazon_variation_id IS NOT NULL)
index_edi_documents_on_catalog_item_id (catalog_item_id) WHERE (catalog_item_id IS NOT NULL)
index_edi_documents_on_edi_communication_log_id (edi_communication_log_id)
index_edi_documents_on_invoice_id (invoice_id) WHERE (invoice_id IS NOT NULL)
index_edi_documents_on_item_id (item_id) WHERE (item_id IS NOT NULL)
index_edi_documents_on_order_id (order_id) WHERE (order_id IS NOT NULL)
index_edi_documents_on_receipt_id (receipt_id) WHERE (receipt_id IS NOT NULL)

Foreign Keys

fk_rails_... (amazon_variation_id => amazon_variations.id) ON DELETE => cascade
fk_rails_... (catalog_item_id => catalog_items.id) ON DELETE => cascade
fk_rails_... (edi_communication_log_id => edi_communication_logs.id) ON DELETE => cascade
fk_rails_... (invoice_id => invoices.id) ON DELETE => cascade
fk_rails_... (item_id => items.id) ON DELETE => cascade
fk_rails_... (order_id => orders.id) ON DELETE => cascade
fk_rails_... (receipt_id => receipts.id) ON DELETE => cascade

Belongs to collapse

Instance Method Summary collapse

Methods inherited from ApplicationRecord

ransackable_associations, ransackable_attributes, ransackable_scopes, ransortable_attributes, #to_relation

Methods included from Models::EventPublishable

#publish_event

Instance Method Details

#amazon_variationAmazonVariation



49
# File 'app/models/edi_document.rb', line 49

belongs_to :amazon_variation, optional: true

#catalog_itemCatalogItem



44
# File 'app/models/edi_document.rb', line 44

belongs_to :catalog_item, optional: true

#edi_communication_logEdiCommunicationLog

belongs_to :resource, polymorphic: true, optional: true



43
# File 'app/models/edi_document.rb', line 43

belongs_to :edi_communication_log

#invoiceInvoice

Returns:

See Also:



47
# File 'app/models/edi_document.rb', line 47

belongs_to :invoice, optional: true

#itemItem

Returns:

See Also:



45
# File 'app/models/edi_document.rb', line 45

belongs_to :item, optional: true

#orderOrder

Returns:

See Also:



46
# File 'app/models/edi_document.rb', line 46

belongs_to :order, optional: true

#receiptReceipt

Returns:

See Also:



48
# File 'app/models/edi_document.rb', line 48

belongs_to :receipt, optional: true

#resourceObject



53
54
55
# File 'app/models/edi_document.rb', line 53

def resource
  catalog_item || item || order || invoice || receipt || amazon_variation
end

#resource=(val) ⇒ Object



57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'app/models/edi_document.rb', line 57

def resource=(val)
  case val
  when CatalogItem
    self.catalog_item = val
  when Item
    self.item = val
  when Order
    self.order = val
  when Invoice
    self.invoice = val
  when Receipt
    self.receipt = val
  when AmazonVariation
    self.amazon_variation = val
  else
    raise ArgumentError, "Unsupported resource type: #{val.class.name}"
  end
end