Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

135
Vistas
How to cast a plain json object to typeorm entity

There is a transformer class called PlainObjectToNewEntityTransformer, if I need to invoke its transform function, I have to pass in the EntityMetadata which requires connection, I think casting doesn’t really need connection. The current workaround is to do the following by just assign in constructor, but this won’t preserve the schema since the field keys are often changed.

@Entity('myentities')
export class MyEntity {
  constructor(partial?: Partial<MyEntity>) {
    if (partial) {
      Object.assign(this, partial);
    }
  }
}

const entity = new MyEntity(json);

I am not sure if the casting can be done in a proper way.

about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda