-
-
Notifications
You must be signed in to change notification settings - Fork 492
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
Assign values generated or calculated by a query to an entity #40
Comments
I will add bool parameter to create method so you can achieve it via single command, it makes sense to allow this. |
Or do you think its better to implement It might be better as you could whitelist properties instead of allowing anything via one boolean. |
I am sure you have more experience with ORMs. If you see some advantage to my proposition, perfect I will use it, else I don't want add maintenance complexity with features used only by me. With the information of your previous response I can do a generic function to solve this, and can be enougth: public static toModel<T>(entities: BaseEntity[], repository: EntityRepository<IEntityType<T>>): Array<IEntityType<T>> {
return entities.map((entity) => {
const model: IEntityType<T> = repository.getReference(entity.id);
model.assign(entity);
return model;
});
} |
Or maybe simply if `assign()´ return the entity, so that it can be done: return entities.map((entity) => this.locationRepository.getReference(entity.id).assign(entity)); instead of: return entities.map((entity) => {
const location: LocationModel = this.locationRepository.getReference(entity.id);
location.assign(entity);
return location;
}); But I prefer you choose, because you know the code better and I don't finish to understand when to use |
Fluent interface to entity.assign() also came to my mind. I will probably do all 3 things, fluent interface for I expect to have some time for this later this week, will ping you here once its published. Or feel free to send PR, 1. and 2. are really small changes. 3. will be probably more challenging and will require some additional tests, I can handle that myself. Btw there is also |
Shadow properties implemented in 6062118 I saw you were forking the repo, are you up to implement 1. and 2.? If not I will do that myself, but will be glad for another collaborator :) |
No, I was trying the MongoDB transactions. I was too ambitious. I can't see how to handle the possible nested transactions. |
Released v2.2 that includes shadow properties. |
Great, I expect to have some time to try it later this week. Thanks. |
This allows to mark properties that will not be persisted into database, but can be assigned via entity manager methods like `create()` or `merge()`. Closes mikro-orm#40
I'm not sure if this feature is out of ambit of a ORM. Feel free of close the issue directly, if so.
I have a entity:
And a query, MongoDB aggregation, that create a new value calculated (distance):
When converting the query result to entity, the value "distance" is ignored and I have to handle it manually. Can be possible implement something to handle it automatically, something like:
The text was updated successfully, but these errors were encountered: