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

Change "model" property from string to object in @prismaRelation decorator #4

Open
juliano-soares opened this issue Aug 4, 2023 · 0 comments
Labels
enhancement New feature or request

Comments

@juliano-soares
Copy link
Member

juliano-soares commented Aug 4, 2023

Description:
Currently, the @prismaRelation decorator uses a string to specify the related model in the Prisma schema. For example:

Before:

@prismaField({ type: Profile })
@prismaRelation({
    relation: Relation.OneToOne,
    model: "Profile",
    refs: ["id"],
    onDelete: Action.Cascade,
    onUpdate: Action.Cascade,
})
profile!: Profile;

Proposal:
I suggest changing the model property from a string to an object reference of the related model. This would improve type safety and make it consistent with how Prisma handles relations in the schema.

After:

@prismaField({ type: Profile })
@prismaRelation({
    relation: Relation.OneToOne,
    model: Profile, // <- Here
    refs: ["id"],
    onDelete: Action.Cascade,
    onUpdate: Action.Cascade,
})
profile!: Profile;

This change will not only enhance the readability of the code but also provide better TypeScript support, as it allows proper type checking and autocompletion when defining relations.

@juliano-soares juliano-soares added the enhancement New feature or request label Aug 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant