This is my first shot at trying to develop an application using some of the ideas behind DDD. It's a Rails monolith application (at-least for now). I know i'm not being strict with DDD, but I'm trying to focus on the separation of my domains which seems like the most important concept.
I think this is probably quite a rudimentary question and I'm sure I'll use the wrong DDD terminology, but here we go...
I have two domains:
- CRM (contacts, companies, branches, people, etc..)
- Quoting (quotes, quote items, currency, etc..)
In the Quoting domain, my Quote model links to a contact_id and company_id in the CRM domain.
On a page in the CRM domain I want to list all the Quotes that belong to a company.
The code is something like this:
module CRM
class QuotesController
def index
@company = Company.find params[:company_id]
@quotes = Quoting::Quote.for_company(@company.id)
end
On this page I want to show who created each quote and I'm not sure what the best way is. The contact_id column in Quote links to the CRM::Contact model, and the CRM::Contact model links to the CRM::Person model which includes the name.
Without thinking of DDD, I would've done something like this (this is simplified) (yes, I know I'm not using associations here):
module Quoting
class Quote < ApplicationRecord
belongs_to :company, class_name: "CRM::Company"
belongs_to :contact, class_name: "CRM::Contact"
class << self
def for_company(company_id)
Quote.where(company_id: company_id)
.includes(contact: :person) <--- feels like it shouldn't be here
end
end
end
end
In the view:
@quotes.each do |quote|
%tr
%td= quote.contact.person.name (or quote.contact_name)
My issue with that is the line .includes(contact: :person)
which includes knowledge about another domain, i.e. it knows that the name is within the person record. If my internal implementation of Contacts/Person changes then obviously this Quoting domain will fail too.
How could this be done in a more DDD style?
Would I have a new Quote model in my CRM domain that would run 2 queries and collate them into a new model?
Thanks!