Skip to content
This repository has been archived by the owner on Oct 10, 2022. It is now read-only.

Abstract class generation #289

Closed

Conversation

ivawzh
Copy link

@ivawzh ivawzh commented Aug 10, 2020

Support abstract class codegen.

The idea is to use the generated classes as abstract classes. Custom domain behaviors (i.e. methods, validations, and lifecycles) may be located in another class that inherits the generated model. This could benefit us from

  1. avoiding polluting when running codegen after migration on existing codes.
  2. have lean models without the boilerplates.
  3. share common behaviors across multiple models.

3 new flags:

  • extendAbstractClass - string. Similar to activeRecord that extends BaseEntity. Now it supports custom abstract class inheritance by passing a relative path as string to extendAbstractClass.
  • exportAbstractClass - boolean. Export the generated models as an abstract class without @Entity
  • skipRelationships - boolean. Skip generating relationship columns. Because currently there is a bug from TypeORM failing at foreign key embedded columns in abstract classes. Plus, too often we will need to rename the relationships anyway.

Close: #288

@ivawzh ivawzh force-pushed the inherit-custom-abstract-class branch 3 times, most recently from a75d1c5 to 2359ee6 Compare August 10, 2020 17:49
@ivawzh ivawzh changed the title Support extend-abstract-class Abstract class generation Aug 10, 2020
@ivawzh ivawzh force-pushed the inherit-custom-abstract-class branch from 2359ee6 to b2ebeb2 Compare August 10, 2020 17:54
The idea is to use the generated classes as abstract classes. Custom domain behaviors (i.e. methods, validations, and lifecycles) may be located in another class that inherits the generated model. This could benefit us from

1. avoiding polluting when running codegen after migration on existing codes.
1. have lean models without the boilerplates.
1. share common behaviors across multiple models.

3 new flags:

- `extendAbstractClass` - string. Similar to `activeRecord` that `extends BaseEntity`. Now it supports custom abstract class inheritance by passing a relative path as string to `extendAbstractClass`.
- `exportAbstractClass` - boolean. Export the generated models as an abstract class without `@Entity`
- `skipRelationships` - boolean. Skip generating relationship columns. Because currently there is a [bug from TypeORM failing at foreign key embedded columns in abstract classes](typeorm/typeorm#3132).

Close: Kononnable#288
@ivawzh ivawzh force-pushed the inherit-custom-abstract-class branch from b2ebeb2 to 894b641 Compare August 10, 2020 18:35
@stale
Copy link

stale bot commented Oct 9, 2020

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label Oct 9, 2020
@stale stale bot closed this Oct 16, 2020
@Kononnable
Copy link
Owner

As I recall this was never a full feathered PR, only a draft. Shame, that GH doesn't show it anywhere here.

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

Successfully merging this pull request may close these issues.

Use custom abstract class
2 participants