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

234
Vistas
get instance fields from a TypeORM entity class

I have an typeorm entity of the following form:

@Entity()
export class User {

    @PrimaryGeneratedColumn()
    id: number;

    @Column()
    firstName: string;

    @Column()
    lastName: string;

    @Column()
    isActive: boolean;
}

Now I am looking to get the instance fields from this entity class into an array, like below:

['id', 'firstName', 'lastName', 'isActive']

How can I achieve that?

I tried the following but with no help:

class Me extends User{
    constructor() {
        super()     
    }
}

const me = new Me()
console.log(Object.keys(me)) // []
about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

Give initial values in your User class to the properties. They are null now, Object.keys wont list them. Try this:

@Entity()
export class User {

    @PrimaryGeneratedColumn()
    id: number = 0;

    @Column()
    firstName: string = "";

    @Column()
    lastName: string = "";

    @Column()
    isActive: boolean = false;
}

Alternative solution is when you fill the attrs manually:

const user = new User();
user.id = 0;
user.firstName = "";
user.lastName = "";
user.isActive = false;
about 4 years ago · Juan Pablo Isaza Denunciar

0

You might be able to do something like this:

const userProps = getConnection()
  .getMetadata(User)
  .ownColumns
  .map(column => column.propertyName);

This means that you obtain metadata from an entity if you take the class function (AKA constructor) and use the .getMetadata method on the DB connection.

Reference:

Get all properties from a entity #1764

about 4 years ago · Juan Pablo Isaza Denunciar
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