How to add relations buried in an embedded entity? #831
-
Hi there. I have been trying to make this work, but no luck so far. I want to create an
A minimal preview would be like the following: @Entity()
export class User {
@PrimaryGeneratedColumn('uuid')
uuid: string
@Column()
name: string
// other fields
}
export abstract class Inspection {
@ManyToOne(() => User)
inspector?: User;
// other fields
}
@Entity()
export class Invoice {
@PrimaryGeneratedColumn('uuid')
uuid: string
@Column(() => Inspection)
quantity?: Inspection
// other fields
} Now, let's say I want to get the invoice, and load the const id = "some-valid-uuid-here"
async findOne(id: string) {
return this.invoiceRepository.findOne({ where: { uuid: id }, relations: ['quantity.inspector'] })
} But I can't get it to work with same relation specification inside paginate config. For instance: static PAGINATION_CONFIG: PaginateConfig<Invoice> = {
// other settings with filter, sortable columns, etc.
relations: ['quantity.inspector'],
// P.S the form below doesn't work as well
// relations: { quantity: { inspector: true } } It raises the error:
P.S: I have read usage-with-relations, I know about the merged pull request Embedded entities #369, I have the latest |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
umm.. embedded entities don't need any relation definition - see https://github.com/ppetzold/nestjs-paginate/blob/master/src/paginate.spec.ts#L1235 both notations Your case where an embedded entity holds another relation is simply an edge case where this lib has no coverage yet - and hence the implementation didn't consider this. You are welcome to submit a bug fix :) |
Beta Was this translation helpful? Give feedback.
umm.. embedded entities don't need any relation definition - see https://github.com/ppetzold/nestjs-paginate/blob/master/src/paginate.spec.ts#L1235
both notations
relations: ['quantity.inspector']
andrelations: { quantity: { inspector: true } }
perform actual table joins, that's why you getting the error above.Your case where an embedded entity holds another relation is simply an edge case where this lib has no coverage yet - and hence the implementation didn't consider this.
You are welcome to submit a bug fix :)