Reputation: 879
I'm struggling to model my queries and read models when it comes to supporting more complicated UIs that support different dimensions of data.
Imagine a scenario where I have an OrderDetailView
, for a screen that displays the details of the order (order lines, etc).
Now imagine a screen that displays those same order details, plus a list of delivery companies who can service the order.
Questions:
Do I create a separate ViewModel
for this screen? I struggle with naming it, but perhaps something like OrderDeliveryView
? Or AssignDeliveryToOrderView
. For these more complicated screens is it good practice to name after the action that will ultimately be performed?
Our read models live in an SQL database. The only way I can see to store the order details, and the list of delivery companies for the view is by using two separate tables. Both tables would be updated from the relevant events via the OrderDeliveryView normalizer.
If that is the case though, is it better to just use the existing OrderDetailView
and call a second query from the UI: GetAvailableDeliveryCompanies
that would return a DeliveryCompanyListView
. These models more closely follow the examples I've seen.
In a nutshell, from your experience, is it better to accept that two tables are needed for this complicated View, and move ahead? Or recognize that "half" of the view is already provided by an existing view, and have the UI make multiple queries?
Upvotes: 1
Views: 461
Reputation: 4098
The Model you use in your UI does not necessarily need to be the same as how you store. I would go for creating a separate ViewModel
for each screen that you have.
That said depending on the technology you may be able to "reuse" your ViewModel
. For example, with ASP.NET there is a concept of Partial View
. That is, you can create a common View
(and ViewModel
) to be reused across multiple screens/ pages.
The Views
/Tables
on the SQL can be optimized for how they are retrieved. But, that does not stop you from having multiple calls to the DB for a single ViewModel
/ screen.
When it comes to the naming of the ViewModel
, I suggest naming it according to the operations it performs on UI rather than coupling it with the data-store.
Upvotes: 2