Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

232
Views
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 answers
Answer question

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 Report

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!