Comments (9)
EntityManager.create()
currently ignores properties that are not marked via decorators. You could create reference instead and use assign to include them:
return entities.map((data) => {
const entity = this.locationRepository.getReference(data._id);
entity.assign(data);
return entity;
});
I will add bool parameter to create method so you can achieve it via single command, it makes sense to allow this.
from mikro-orm.
Or do you think its better to implement @Property({ persist: false })
? Should be pretty easy.
It might be better as you could whitelist properties instead of allowing anything via one boolean.
from mikro-orm.
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;
});
}
from mikro-orm.
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 EntityRepository.create()
or new Entity()
and Entity.assign()
(Surely I will ask you at stackoverflow about this).
from mikro-orm.
Fluent interface to entity.assign() also came to my mind. I will probably do all 3 things, fluent interface for entity.assign()
, boolean toggle for EM.create()
to allow extra properties, and @Propery({ persist: false: })
so one can whitelist only specific properties that are allowed.
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 EM.merge()
, that behaves similarly to EM.create()
:] I will definitely write something about this into docs later, but you can check tests to see how those things differ in the meanwhile. Currently I am trying to gather some feedback on reddit and once I have enough, I will create FAQ page. I also published an article about MikroORM: https://medium.com/dailyjs/introducing-mikro-orm-typescript-data-mapper-orm-with-identity-map-9ba58d049e02
from mikro-orm.
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 :)
from mikro-orm.
No, I was trying the MongoDB transactions. I was too ambitious. I can't see how to handle the possible nested transactions.
from mikro-orm.
Released v2.2 that includes shadow properties.
from mikro-orm.
Great, I expect to have some time to try it later this week.
Thanks.
from mikro-orm.
Related Issues (20)
- Serialised entity is populated instead of FK HOT 2
- pnpm + vitest + esm+ MikroORM.init = Unknown file extension ".ts"
- Extra query fired when fetching a join table entity and populating a join column HOT 1
- docs: Unwrapping Nested Objects using Embeddables or Custom Types
- Can't debug findOne results in VSCode when instance is populated with related OneToMany / ManyToMany relation.
- Optimistic locking not working with upsert HOT 3
- Setting LockMode with disabled identity map results in error
- Extra updates on embedded entities with camelCase field name HOT 2
- docs: Comparison with other ORM / query builder / SQL libraries
- Modules for DB Dialetica not Found
- Entity discovery on TsMorphMetadataProvider broken since 6.2.2
- Custom types return null when using postgres with a type set on the property definition
- The decorator @AfterUpdate() and classes what implements from EventSubscriber don't work for my project
- SUM function in query builder has incorrect syntax. HOT 2
- SQLite returns timestamp for date fields defined by `t.datetime` in a populated entity HOT 4
- Add support for non-persistent Embedded properties in entities
- MikroOrm upgrade to v6 throws error Cannot read properties of undefined (reading 'values')
- [Bug]: Formula set as ScalarReference not loaded as LoadedScalarReference at runtime HOT 6
- matching doesn't set _populated to true HOT 4
- Order by doesn’t work with embeddable fields inside populated entity if embedabble has object true
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from mikro-orm.