You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[Question] How do you handle "types" or "states"? As value object? If so, do we store them in database? #288
let's say your Batch in the book, needs to have an attribute of string type called state with the following values: fulfilled, partial, unfulfilled, cancelled as the only possibilities
How do you represent those values?
Do you use value objects? Do you use them as value objects and also store the values in the database in their own tables? I know for sure you will have to store the value within the Batch table
If these should be value objects, maybe that might make #237 issue more solvable
Because it's natural to think that fulfilled is > partial and partial is > unfulfilled though cancelled is not meant to be meaningfully compared with any of the three.
I would usually store the values in the database in the same row as the containing entity, and map those back to value objects in code. Enums, for example, are a kind of value object, and SqlAlchemy has support for converting them to and from database tables.
What if the same enums are used in more than one containing entity?
E.g. you have Batch and also Order in the same domain context using the enum days. Sorry I know this is a very forced example because your book separates teh allocation domain from the customer purchasing domain. But I'm thinking out loud.
SO basically both Batch and Order has a string attribute called day_of_week and both entities allow that attribute to have any value from Monday to Sunday.
Would you still handle it the same way?
What if one containing entity only allows a subset of the full list of the possible values?
And does this mean that when you use value object and not stored in database, you're essentially saying that the user cannot define new values for that particular value object?
Activity
bobthemighty commentedon Apr 23, 2020
I would usually store the values in the database in the same row as the containing entity, and map those back to value objects in code. Enums, for example, are a kind of value object, and SqlAlchemy has support for converting them to and from database tables.
simkimsia commentedon Apr 28, 2020
Thanks for reply @bobthemighty
What if the same enums are used in more than one containing entity?
E.g. you have
Batchand alsoOrderin the same domain context using the enumdays. Sorry I know this is a very forced example because your book separates teh allocation domain from the customer purchasing domain. But I'm thinking out loud.SO basically both
BatchandOrderhas a string attribute calledday_of_weekand both entities allow that attribute to have any value from Monday to Sunday.Would you still handle it the same way?
What if one containing entity only allows a subset of the full list of the possible values?
And does this mean that when you use value object and not stored in database, you're essentially saying that the user cannot define new values for that particular value object?
🙏 for the awesome book you and Harry worked on