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

Support Single Table Subclasses #248

Closed
stephenh opened this issue Feb 21, 2022 · 1 comment
Closed

Support Single Table Subclasses #248

stephenh opened this issue Feb 21, 2022 · 1 comment

Comments

@stephenh
Copy link
Collaborator

stephenh commented Feb 21, 2022

In the past I've generally preferred class-per-table subclasses, but it might be neat to support single-table subclasses with a scheme like:

Designate a type column and determines the subclass in joist-codegen.json:

UserEvent: {
  fields: {
    type: {
      subclasses: {
        COMMENTED: { name: "CommentUserEvent", fields: ["comment"] },
        LIKED: { name: "LikeUserevent", fields: ["post", "author"] },
      }
    }
  }

Or maybe re-arranged slightly:

UserEvent: {
  subclassDiscriminator: "type",
  subclasses: {
    COMMENTED: { name: "CommentUserEvent", fields: ["comment"] },
    LIKED: { name: "LikeUserEvent", fields: ["post", "author"] },
  }

And then codegen would output:

  • UserEventCodegen.ts as-is
  • UserEvent.ts as-is
  • CommentUserEventCodegen.ts, new, extends UserEvent, marks comment as required
  • CommentUserEvent.ts, new, touched once, for subclass-specific business logic.

Questions:

  • How do handle m2os to "only a subclass" i.e. only a CommentUserEvent. In CPTI (class per table), the m2o FK just points to the subclass column
@stephenh
Copy link
Collaborator Author

stephenh commented Mar 3, 2024

Implemented in #966

@stephenh stephenh closed this as completed Mar 3, 2024
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

1 participant