nestjs-paginate
nestjs-paginate copied to clipboard
problem with view entity with composite primary key
When we want to run pagination on the view entity without ID, and has 2 primary keys, when active load relation on primary keys relation, the result data field is empty but total items is correct
@ViewEntity({
name: 'projects_and_simulated_projects',
materialized: false,
expression: `
// .... some query
`,
dependsOn: [Project, Simulation],
})
export class ProjectsWithSimulatedProjects {
@ViewColumn({
name: 'project_id',
})
@PrimaryColumn({
name: 'project_id',
})
@ManyToOne(
() => Project,
(project) => project.id,
{ eager: false },
)
@JoinColumn({ name: 'project_id', referencedColumnName: 'id' })
project: Project;
@ViewColumn({
name: 'simulation_id',
})
@PrimaryColumn({
name: 'simulation_id',
})
@ManyToOne(
() => Simulation,
(simulation) => simulation.id,
{ eager: false },
)
@JoinColumn({ name: 'simulation_id', referencedColumnName: 'id' })
simulation: Simulation;
//... other fields that are shared between the project and simulation entity
}
in the above view entity when we try to run pagination without loading relations everything works fine, but when loading relations with query builder or pagination config the result has the actual total number of items but the data property is an empty array
I tried to debug the query and figured out that the query only ran using the second primaryColumn field
also, make eager true not working and only id returned in the field
possibly related to the snake case column names?
try this: https://github.com/ppetzold/nestjs-paginate/issues/641#issuecomment-1707477638
No, I use typeorm-naming-strategies for my column names but it is not working with/without it
have you checked the generated SQL? does it look alright?
@ppetzold Yes
I tried to debug the query and figured out that the query only ran using the second
primaryColumnfield