Skip to content

Normalizing State Shape #2771

@StevenXL

Description

@StevenXL

Hi Folks,

I want to update the Normalizing State Shape docs.

I'm 100% on-board normalized state shape, and its benefits. However, while the docs allude to using the principles of database design whenever possible, it seems like the current docs go against this idea.

What I mean is that we have a relationship in the docs where a Post has many Comments. We model this relationship by having a Post object contain a comments key, which is an array of comment ids. If we were to follow database design principles, shouldn't the comment have a postId property indicating which post it belongs to? In other words, shouldn't the "foreign key" be on the comment, rather than on the post?

I'd like to propose two changes to the docs:

  1. Change the docs so that the "foreign key" is on the Comment, not on the Post.
  2. Change the docs so that we don't keep a list of allIds, since it seems to me that this is data that can be calculated, and therefore shouldn't be stored.

I haven't made a PR of these changes because I am not sure if I am missing something, but if a project maintainer thinks these changes would be improvements, I'd be happy to make a PR on it.

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