Skip to content

API Generator: Add support for extending entities #3846

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

Merged
merged 2 commits into from
May 13, 2025

Conversation

kaufmo
Copy link
Contributor

@kaufmo kaufmo commented May 8, 2025

Description

Add support for extending entities in API Generator.

Example

@Entity({ abstract: true })
export abstract class TimestampEntity extends BaseEntity {
    @Property({
        columnType: "timestamp with time zone",
    })
    @Field()
    createdAt: Date = new Date();

    @Property({ onUpdate: () => new Date(), columnType: "timestamp with time zone" })
    @Field()
    updatedAt: Date = new Date();
}

@Entity()
export class TestEntityWithTimestamps extends TimestampEntity {
    @PrimaryKey({ type: "uuid" })
    id: string = uuid();

    @Property()
    foo: string;
}

NOTE: We don't recommend inheritance for code reusage

Limits

This is just basic support, it will probably break when the base class involves root blocks or enums (where we depend on ts-morph)

@kaufmo kaufmo requested a review from johnnyomair May 8, 2025 15:02
@kaufmo kaufmo self-assigned this May 8, 2025
@kaufmo kaufmo changed the base branch from main to next May 8, 2025 15:02
@kaufmo kaufmo changed the title DRAFT: API Generator: Allow extending of mikro-orm entities Draft: API Generator: Allow extending of mikro-orm entities May 8, 2025
@kaufmo kaufmo marked this pull request as draft May 9, 2025 03:30
@nsams nsams marked this pull request as ready for review May 9, 2025 08:37
@nsams nsams changed the title Draft: API Generator: Allow extending of mikro-orm entities API Generator: Allow extending of mikro-orm entities May 9, 2025
@johnnyomair johnnyomair changed the title API Generator: Allow extending of mikro-orm entities API Generator: Add support for extending entities May 13, 2025
@johnnyomair johnnyomair merged commit ce6d3cd into next May 13, 2025
11 checks passed
@johnnyomair johnnyomair deleted the crud/extend-entities branch May 13, 2025 12:34
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

Successfully merging this pull request may close these issues.

3 participants