ppetzold/nestjs-paginate

relations are not loaded when the select option is provided

Closed this issue · 2 comments

When I disable the select option, the company company field relation works.

  const { data } = await paginate(req.query, Administrator.getRepository(), {
    relations: ['company'],
    defaultSortBy: [['createTime', 'DESC']],
    sortableColumns: Administrator.safeColumnNames,
    // select: Administrator.safeColumnNames,
    searchableColumns: Administrator.safeColumnNames,
    filterableColumns: Object.fromEntries(Administrator.safeColumnNames.map((key) => [key, true])),
  })

However, when I enable it, relations are no longer loaded!

  const { data } = await paginate(req.query, Administrator.getRepository(), {
    relations: ['company'],
    defaultSortBy: [['createTime', 'DESC']],
    sortableColumns: Administrator.safeColumnNames,
    select: Administrator.safeColumnNames,
    searchableColumns: Administrator.safeColumnNames,
    filterableColumns: Object.fromEntries(Administrator.safeColumnNames.map((key) => [key, true])),
  })

For making the example more obvious,

Administrator.safeColumnNames = [ "companyId", "id", "createTime", "firstName", "lastName" ]

Also, there's a workaround for making this work, but it needs so much work,

Administrator.safeColumnNames = [ "companyId", "id", ..., "company(name)", "company(email)", "company(id)" ... and so on ]

Can you create a simple way to simply say "company", and when "company" is selected, everything inside it will automatically be loaded (of couse by taking into account the select option in the entity)?

You gotta select the primary key of each relation.. company.id