Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Question] How do you handle "types" or "states"? As value object? If so, do we store them in database? #288

Open
simkimsia opened this issue Apr 23, 2020 · 2 comments

Comments

@simkimsia
Copy link

simkimsia commented Apr 23, 2020

How do you handle "types" or "states"?

Let me give you an example:

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.

Perhaps the use of dry-python and result container might be interesting here https://github.com/dry-python/returns#result-container

@bobthemighty
Copy link
Contributor

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
Copy link
Author

Thanks for reply @bobthemighty

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?

🙏 for the awesome book you and Harry worked on

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants