Skip to content

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

Open

Description

@simkimsia

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

Activity

  1. bobthemighty commented on Apr 23, 2020

    @bobthemighty
    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.

  2. simkimsia commented on Apr 28, 2020

    @simkimsia
    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions