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)
- Allow setting `name` explicitly when `class` is set when using EntitySchema to define entities
- QueryBuilder in 6.2.x HOT 12
- Typescript error after upgrade from 6.1.12 to 6.2.2
- The migration:check command exits with ERR_IMPORT_ASSERTION_TYPE_MISSING HOT 3
- On MariaDB, It updates JSON column which not changed. HOT 11
- Upsert with Embeddings gives InvalidFieldNameException Postgresql
- Cursor pagination `first: 0` returns all items HOT 1
- Infinite cycle when querying an entity HOT 2
- Cannot find matching entity for condition" when using upsertMany HOT 1
- there is not enough being logged when having an index conflict in mongodb
- OnCreate property hook not executed when using Scalar Reference HOT 1
- "Source file '...' not found." error occurs since version 6.2.2-dev.7 with Bun. HOT 2
- PostgreSQL malformed query when using query builder, joining a sub-query + ManyToMany where-condition + setting a limit
- MikroORM should merge all changes of one record into one sql update statement HOT 1
- 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
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.