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

Custom decorator? #2711

Closed
leesiongchan opened this issue Aug 26, 2018 · 4 comments
Closed

Custom decorator? #2711

leesiongchan opened this issue Aug 26, 2018 · 4 comments
Labels

Comments

@leesiongchan
Copy link

Issue type:

[ ] question
[ ] bug report
[x] feature request
[ ] documentation issue

Database system/driver:

[ ] cordova
[ ] mongodb
[ ] mssql
[ ] mysql / mariadb
[ ] oracle
[x] postgres
[ ] sqlite
[ ] sqljs
[ ] react-native
[ ] expo

TypeORM version:

[x] latest
[ ] @next
[ ] 0.x.x (or put your version here)

Steps to reproduce or a small repository showing the problem:

How if I want to create a custom decorator say for example a blameable decorator?

@Kononnable
Copy link
Contributor

I don't see how creating custom decorator is related to ORM. Could you describe your issue(if it is related to typeorm)?

@leesiongchan
Copy link
Author

leesiongchan commented Sep 30, 2018

I mean a column decorator, like @CreateDateColumn or @UpdateDateColumn, what if I want to create a custom column decorator like @CreateCreatorColumn or @UpdateCreatorColumn? Or can we have an example in doc?

@Kononnable
Copy link
Contributor

It really depends on what you want to do. Look at existing decorator - it just stores some metadata which is used later in ORM logic. You can use e.g. custom subscriber to act on yours metadata.

export function UpdateDateColumn(options?: ColumnOptions): Function {
return function (object: Object, propertyName: string) {
getMetadataArgsStorage().columns.push({
target: object.constructor,
propertyName: propertyName,
mode: "updateDate",
options: options ? options : {}
} as ColumnMetadataArgs);
};
}

@leesiongchan
Copy link
Author

Yea, but it doesn't seem to have the flexibility to add your custom metadata, ORM later uses mode to determine the logic I believe.

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

No branches or pull requests

2 participants