Skip to content

Instantly share code, notes, and snippets.

@dmitryzuev
Created May 4, 2020 07:47
Show Gist options
  • Save dmitryzuev/00aa6663f5db84345cf7a1de091fd29c to your computer and use it in GitHub Desktop.
Save dmitryzuev/00aa6663f5db84345cf7a1de091fd29c to your computer and use it in GitHub Desktop.
class Customer < ApplicationRecord
has_many :customer_documents
has_many :documents, through: :customer_documents
end
class CustomerDocument < ApplicationRecord
belongs_to :customer
belongs_to :document
end
class Document < ApplicationRecord
belongs_to :document_type
has_many :customer_documents
has_many :customers, through: :customer_documents
end
class DocumentType < ApplicationRecord
has_many :documents
has_many :customers, -> { distinct }, through: :documents
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment