Working with Entities (In Subscribers?)
See original GitHub issueHello,
I’d like to be able to work with an Entity that is sent to my server, whether the full object is sent, or only part of it.
i.e.
Say we have two tables, Meal
, and MealHistory
. If someone ordered a meal, it is in the Meal
table, when it is complete it gets moved to the MealHistory
table.
The full meal object is { id: int, name: string, quantity: int, complete: boolean }
Which belongs to the Meal table, the MealHistory
table has the exact same structure.
When a meal is completed, it is moved to the MealHistory
table.
I want to be able to move the Meal object by only passing the PK, and complete field like:
{ id: 1, complete: true }
However, to do this, we need to pass the whole object to add the complete record into MealHistory
, additionally, I am not able to remove the original record from the Meal
table.
My questions are
- How can I get the whole object at this point?
- How can I remove the original object after it has been saved in history?
Right now I am trying to get around this with subscribers. I am on alpha 31.
Thanks
Issue Analytics
- State:
- Created 6 years ago
- Comments:7 (3 by maintainers)
event.manager is
EntityManager
which has all method to access any table, or even get a repository for entity you need, e.g.event.manager.getRepository(Post)
again you forgot to await
remove
in your code. Please don’t forget to await your promises or you’ll end up creating lot of issues in this repo, I don’t have a time to answer them each time.But your problem here is different. If you want to perform database operations use
event.manager
and only it to do that. Don’t usegetEntityManager()
orgetRepository()
or any other global function.This is due to a transaction. Save is running in a transaction and your data is saved in a transaction which is not committed yet. But global functions you use are running out of transaction.