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

Any way to determine entity state? #1711

Open
icguy opened this issue Mar 22, 2023 · 1 comment
Open

Any way to determine entity state? #1711

icguy opened this issue Mar 22, 2023 · 1 comment

Comments

@icguy
Copy link

icguy commented Mar 22, 2023

tl;dr: Is there any way of determining whether a DAO entity is being inserted, deleted or updated in the current transaction?

Context: I am maintaining an entity change tracker that needs to detect:

  • every insert (table, entity id)
  • every update (table, entity id, updated column, previous and current values)
  • every delete (table, entity id)

Leveraging Exposed's EntityHooks I get notified about the inserts and deletes but the updates get flushed before I am able to extract the updated values from writeValues and readValues. See the source.

This has lead me to extract the changes by overriding the entity flush function and log the changes before forwarding to the original flush, but then I cannot differentiate between updated and inserted entities. My best bet currently is to access the internal isNewEntity function via reflection.

Hence the question: is there any recommended way I can determine entity state? Or is there some other less convoluted approach I can take to implement my change tracker?

@AlexeySoshin
Copy link
Contributor

Hi,
I took a look at the code as well, and from what I can tell, there's no better way at the moment.
The reason the flush occurs before notifying listeners is to avoid race conditions (see 0.40.0 bugs section).
I think it's worth considering making isNewEntity function public instead of internal.

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

No branches or pull requests

2 participants