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

feat(Model): Ability to pass TypeORM Entity options #282

Merged
merged 4 commits into from Dec 18, 2019

Conversation

@jlemm45
Copy link
Contributor

jlemm45 commented Dec 16, 2019

Problem
When using the Model decorator sometimes it's necessary to specific the table name explicitly. For instance in the case of a model named category, I want the table to be named categories. As it sits, warthog would name it categorys

Solution
Ability to use the standard Entity options TypeORM provides. Since the Model decorator essentially wraps the Entity decorator anyway, allow the use of the same options.

Usage
@Model({ name: 'categories' })

I can add an example for this if need be.


import { ClassType } from '../core';
import { getMetadataStorage } from '../metadata';
import { ClassDecoratorFactory, composeClassDecorators, generatedFolderPath } from '../utils/';

export function Model() {
// Allow default TypeORM options to be used
export function Model(entityOptions: EntityOptions = {}) {

This comment has been minimized.

Copy link
@goldcaddy77

goldcaddy77 Dec 17, 2019

Owner

Will need to allow for TypeQraphQL options to be passed, too. Perhaps we could use the same signature as CustomField With api and db https://github.com/goldcaddy77/warthog/blob/master/src/decorators/CustomField.ts#L22

}

// Allow default TypeORM and TypeGraphQL options to be used
export function Model({ api = {}, db = {} }: ModelOptions = {}) {

This comment has been minimized.

Copy link
@jlemm45

jlemm45 Dec 17, 2019

Author Contributor

@goldcaddy77 LMK if this seems to align with your thoughts.

This comment has been minimized.

Copy link
@goldcaddy77

goldcaddy77 Dec 18, 2019

Owner

This looks great. I'll probably add some shortcuts at some point but this would unblock you

jlemm45 added 2 commits Dec 17, 2019
}

// Allow default TypeORM and TypeGraphQL options to be used
export function Model({ api = {}, db = {} }: ModelOptions = {}) {

This comment has been minimized.

Copy link
@goldcaddy77

goldcaddy77 Dec 18, 2019

Owner

This looks great. I'll probably add some shortcuts at some point but this would unblock you

@goldcaddy77 goldcaddy77 merged commit 493c1b2 into goldcaddy77:master Dec 18, 2019
1 check passed
1 check passed
ci/circleci: build Your tests passed on CircleCI!
Details
@goldcaddy77

This comment has been minimized.

Copy link
Owner

goldcaddy77 commented Dec 18, 2019

🎉 This PR is included in version 1.51.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

jlemm45 added a commit to jlemm45/warthog that referenced this pull request Dec 18, 2019
* feat: Ability to pass TypeORM Entity options

* Add ability to pass TypeGraphQL options

* Update README

* Update README
goldcaddy77 added a commit that referenced this pull request Dec 19, 2019
* feat: Ability to pass TypeORM Entity options

* Add ability to pass TypeGraphQL options

* Update README

* Update README
thiagozf pushed a commit to thiagozf/warthog that referenced this pull request Jan 8, 2020
* feat: Ability to pass TypeORM Entity options

* Add ability to pass TypeGraphQL options

* Update README

* Update README
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.