You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Is your feature request related to a problem? Please describe.
When implementing multi-tenancy there is no (clear) way to automatically populate a tenant_id column from a filter previously set on the EntityManager during initialization.
Describe the solution you'd like
Pass the current EntityManager instance to onCreate calls, perhaps as a second argument.
Describe alternatives you've considered
Using the RequestContext class to get the current EntityManager in the onCreate call is possible. This is a very fragile solution and can lead to a lot of potential edge cases if the AsyncLocalStorage is cleaned up before execution of the hook or RequestContext class references differ though.
The text was updated successfully, but these errors were encountered:
Using the RequestContext class to get the current EntityManager in the onCreate call is possible. This is a very fragile solution and can lead to a lot of potential edge cases if the AsyncLocalStorage is cleaned up before execution of the hook or RequestContext class references differ though.
This feels like you are afraid of problems that are not there, the ALS solution seems to be pretty stable to me, you won't get this executed outside of the context, as it gets executed only during flush.
Another more explicit alternative is beforeCreate hook where you already get access to the current EM.
I don't mind doing this, but its not like "there is no clear way", or that the solution you already have would be bad.
Thanks for your quick reply! I've personally run into issues with context loss using the ALS solution, which is why I'm suggesting an alternative in the first place. While use of the beforeCreate hook seems promising, I believe directly passing the EntityManager to onCreate could make my current implementation simpler and more robust.
Is your feature request related to a problem? Please describe.
When implementing multi-tenancy there is no (clear) way to automatically populate a tenant_id column from a filter previously set on the EntityManager during initialization.
Describe the solution you'd like
Pass the current EntityManager instance to onCreate calls, perhaps as a second argument.
Describe alternatives you've considered
Using the RequestContext class to get the current EntityManager in the onCreate call is possible. This is a very fragile solution and can lead to a lot of potential edge cases if the AsyncLocalStorage is cleaned up before execution of the hook or RequestContext class references differ though.
The text was updated successfully, but these errors were encountered: