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
Add support for entity independent hooks/subscribers #516
Comments
As discussed on slack, you could use base entity and define the hooks there, so they will be fired for all entities that extend this base entity. I am planning to add support for something similar to EntitySubscriber in v4 (not necessarily in 4.0 though). |
B4nan
changed the title
Migration from TypeORM
Add support for entity independent hooks/subscribers
May 7, 2020
B4nan
added a commit
that referenced
this issue
Jun 21, 2020
Use `EventSubscriber` to hook to multiple entities or if you do not want to pollute the entity prototype. All methods are optional, if you omit the `getSubscribedEntities()` method, it means you are subscribing to all entities. ```typescript @subscriber() export class EverythingSubscriber implements EventSubscriber { async afterCreate<T>(args: EventArgs<T>): Promise<void> { ... } async afterDelete<T>(args: EventArgs<T>): Promise<void> { ... } async afterUpdate<T>(args: EventArgs<T>): Promise<void> { ... } async beforeCreate<T>(args: EventArgs<T>): Promise<void> { ... } async beforeDelete<T>(args: EventArgs<T>): Promise<void> { ... } async beforeUpdate<T>(args: EventArgs<T>): Promise<void> { ... } onInit<T>(args: EventArgs<T>): void { ... } } ``` Closes #516
B4nan
added a commit
that referenced
this issue
Jun 21, 2020
Use `EventSubscriber` to hook to multiple entities or if you do not want to pollute the entity prototype. All methods are optional, if you omit the `getSubscribedEntities()` method, it means you are subscribing to all entities. ```typescript @subscriber() export class EverythingSubscriber implements EventSubscriber { async afterCreate<T>(args: EventArgs<T>): Promise<void> { ... } async afterDelete<T>(args: EventArgs<T>): Promise<void> { ... } async afterUpdate<T>(args: EventArgs<T>): Promise<void> { ... } async beforeCreate<T>(args: EventArgs<T>): Promise<void> { ... } async beforeDelete<T>(args: EventArgs<T>): Promise<void> { ... } async beforeUpdate<T>(args: EventArgs<T>): Promise<void> { ... } onInit<T>(args: EventArgs<T>): void { ... } } ``` Closes #516
B4nan
added a commit
that referenced
this issue
Aug 2, 2020
Use `EventSubscriber` to hook to multiple entities or if you do not want to pollute the entity prototype. All methods are optional, if you omit the `getSubscribedEntities()` method, it means you are subscribing to all entities. ```typescript @subscriber() export class EverythingSubscriber implements EventSubscriber { async afterCreate<T>(args: EventArgs<T>): Promise<void> { ... } async afterDelete<T>(args: EventArgs<T>): Promise<void> { ... } async afterUpdate<T>(args: EventArgs<T>): Promise<void> { ... } async beforeCreate<T>(args: EventArgs<T>): Promise<void> { ... } async beforeDelete<T>(args: EventArgs<T>): Promise<void> { ... } async beforeUpdate<T>(args: EventArgs<T>): Promise<void> { ... } onInit<T>(args: EventArgs<T>): void { ... } } ``` Closes #516
B4nan
added a commit
that referenced
this issue
Aug 9, 2020
Use `EventSubscriber` to hook to multiple entities or if you do not want to pollute the entity prototype. All methods are optional, if you omit the `getSubscribedEntities()` method, it means you are subscribing to all entities. ```typescript @subscriber() export class EverythingSubscriber implements EventSubscriber { async afterCreate<T>(args: EventArgs<T>): Promise<void> { ... } async afterDelete<T>(args: EventArgs<T>): Promise<void> { ... } async afterUpdate<T>(args: EventArgs<T>): Promise<void> { ... } async beforeCreate<T>(args: EventArgs<T>): Promise<void> { ... } async beforeDelete<T>(args: EventArgs<T>): Promise<void> { ... } async beforeUpdate<T>(args: EventArgs<T>): Promise<void> { ... } onInit<T>(args: EventArgs<T>): void { ... } } ``` Closes #516
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi, I want to migrate my app from TypeORM to MikroORM. Now I've a problem with event listening.
In TypeORM I've a EntitySubscriberInterface injectable by @subscriber() that hook all events afterUpdate, beforeUpdate or other into an external handler and not directly into the entity. This is very useful to manage some events from external.
There is an alternative into MikroORM?
The text was updated successfully, but these errors were encountered: