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

413
Views
Nestjs typeorm relación orden y elementos de límite

Soy nuevo en las relaciones y typeorm. Y ahora tiene algunos problemas con ellos. Y ahora un poco confundido. ¿Es posible en la relación de ordenación typeorm por id o createdDate sin mapearlo y tener elementos límite? Mi ejemplo de código a continuación:

persona.entidad

 @Entity() export class Person { @PrimaryGeneratedColumn() public id!: number; @Column({ type: 'varchar', length: 120 }) public firstName: string; @Column({ type: 'varchar', length: 120 }) public lastName: string; @Column({ type: 'varchar', length: 13 }) public phone: string; @Column({ type: 'varchar', length: 500 }) public place: string; @Column({ type: 'boolean', default: false }) public isDeleted: boolean; @OneToMany(() => Event, (event) => event.person, { onDelete: 'SET NULL', }) public events: Event[]; @CreateDateColumn({ type: 'timestamp' }) public createdAt!: Date; @UpdateDateColumn({ type: 'timestamp' }) public updatedAt!: Date; }

evento.entidad

 @Entity() export class Event { @PrimaryGeneratedColumn() public id!: number; @ManyToOne(() => Person, (person) => person.id, { onDelete: 'CASCADE', }) public person!: Person; @ManyToOne(() => User, (user) => user.id, { onDelete: 'CASCADE', }) public user!: User; @CreateDateColumn({ type: 'timestamp' }) public createdAt!: Date; @UpdateDateColumn({ type: 'timestamp' }) public updatedAt!: Date; }

Mi código para ordenar

 // get persons and sort events public async getALlPersons(): Promise<Person[]> { return this.repository .find({ relations: ['events'], order: { createdAt: 'DESC', }, }) .then((persons) => persons.map((person) => { person.events.sort((a, b) => b.id - a.id); return person; }), ); }

¿Y cómo limitar la cantidad de eventos por persona, por ejemplo, quiero mostrar solo 10 eventos?

Gracias

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Hay un problema de typeorm relacionado con esto: https://github.com/typeorm/typeorm/issues/89 .

Pero en resumen, no es posible.

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!