I am new to DDD and I am having trouble structuring an object. I have a cart
, where I can add products
to it. Each product
has some properties like image, title, price, etc. Whenever a product
is added to the cart
, the database stores this relation in a separate table, called cart_products
. This new table allows me to add some new properties to the cart product
, like an observation, it has an id different from that of the product
in the products
table, it can have additionals like "fries for a cheeseburguer", so on. So, if I am working on a cart
object, which has products
(which come from the cart_products
table), should I have a cart.products
, which would be an array of products
, where each product
will be a cart_product
, with an id, observation and then a property product
which has all the properties of product, like image, title, price, or I can have all these properties directly inside my product? Basically.
cart = {
products = [ // this product comes from `cart_products` table
id = 1
observation = 'text text text'
product = { // this product comes from `products` table
image: 'url'
name: 'Cheese'
price: 2.0
}
]
}
or
cart = {
products = [
{ // this product comes from `cart_products` table
id = 1
observation = 'text text text'
image: 'url' // this property comes from `products` table
name: 'Cheese' // this property comes from `products` table
price: 2.0 // this property comes from `products` table
}
]
}
Using the idea of Ubiquitous Language, it seems like the second fits better, but I don't know it that's correct (or, at least, makes more sense)
cart_product
array for the particular cart instead?prop
an item insidecart.products
. For my use case, it seems like both ideas apply well, but I'd like to know if there's any "better" solution, since thecart product
is actually made of aproduct
and additional info from thecart_product
table, something like an aggregate.cart_product
is put back on the shelf, is it still acart_product
? At home, do they becomeshelf_product
when in the cupboard? . Composingproduct
s as part of a collection is not cause to change type. Here there is a fatal flaw of corrupting domain design because the data store has a join-table.