Code Monkey home page Code Monkey logo

Comments (9)

B4nan avatar B4nan commented on May 13, 2024

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.

B4nan avatar B4nan commented on May 13, 2024

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.

 avatar commented on May 13, 2024

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.

 avatar commented on May 13, 2024

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.

B4nan avatar B4nan commented on May 13, 2024

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.

B4nan avatar B4nan commented on May 13, 2024

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.

 avatar commented on May 13, 2024

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.

B4nan avatar B4nan commented on May 13, 2024

Released v2.2 that includes shadow properties.

from mikro-orm.

 avatar commented on May 13, 2024

Great, I expect to have some time to try it later this week.

Thanks.

from mikro-orm.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.