nestjs-paginate icon indicating copy to clipboard operation
nestjs-paginate copied to clipboard

TypeError: Cannot read properties of undefined (reading 'databaseName')

Open RelatableApp opened this issue 1 year ago • 7 comments

I am using the configuration from the example using the repository method but it gives TypeError: Cannot read properties of undefined (reading 'databaseName'). TypeORM version 0.3.20 nestjs-paginate version 9.1.2

this is my service

async findAll(query: PaginateQuery): Promise<Paginated<Sessions>> {
    try {
      const result = await paginate(query, this.sessionRepo, {
        relations: { files: true, transcript: true },
        sortableColumns: ['id', 'name', 'is_active', 'timeTaken'],
        nullSort: 'last',
        defaultSortBy: [['created_at', 'DESC']],
        searchableColumns: ['name', 'id', 'user_id', 'files.url'],
        filterableColumns: {
          user_id: [FilterOperator.EQ],
          'files.url': [
            FilterOperator.CONTAINS,
            FilterOperator.EQ,
            FilterOperator.ILIKE,
          ],
        },
      });
      return result;
    } catch (error) {
      console.log(error);
    }
  }

RelatableApp avatar Oct 26 '24 14:10 RelatableApp

Can you post the full error log please? And can you show how this.sessionRepo is created? I think there's going to be a not nestjs-paginate related error in your module setup. I'd need the error to know for sure.

Helveg avatar Oct 27 '24 08:10 Helveg

I think this might be due to that 'files.url' part on the searchableColumns. I'm facing the same issue when trying to sort by a field inside a JSON column

williamaditama avatar Nov 05 '24 19:11 williamaditama

I'm facing the same issue. It's related to the nullSort parameter in my case. When I remove it, it works fine!

AliRezaBeitari avatar Dec 05 '24 19:12 AliRezaBeitari

I'm facing the same issue. It's related to the nullSort parameter in my case. When I remove it, it works fine!

This worked for me too thanks

NeniEmSu avatar Jan 24 '25 11:01 NeniEmSu

I think this might be due to that 'files.url' part on the searchableColumns. I'm facing the same issue when trying to sort by a field inside a JSON column

I think so too. I just encountered this issue while trying to sort on a relation column.

I'm facing the same issue. It's related to the nullSort parameter in my case. When I remove it, it works fine!

It's not really a solution to remove things that are broken though, right? I would prefer nullSort or relation sorting to work the way it's advertised.

homj avatar Mar 17 '25 12:03 homj

If I understand correctly there's 2 different issues going on here leading to the same error? One where nullSort causes the error, and one where using a JSON column causes the error? Could someone create a PR with reproducing test cases? Then I can look into a fix from there.

Helveg avatar Mar 18 '25 15:03 Helveg

@Helveg I created a PR for the nullSort issue: https://github.com/ppetzold/nestjs-paginate/pull/1063

AliRezaBeitari avatar Mar 22 '25 07:03 AliRezaBeitari

@AliRezaBeitari I did manage to fix it, by looking into typeorm source the problem is as usually inside :) and they have numerouse of bugs reporting this error

https://github.com/ppetzold/nestjs-paginate/pull/1089

I did manage to fix it, by adding a field to select statement and sort by it, that way typeorm can recognise this field when we have join... it works, and it isolated to mysql and nulllast functionality, so I think it relatively safe to merge it, no breaking changes expect

@Helveg @ppetzold please take a look when time allows

vsamofal avatar Jul 04 '25 17:07 vsamofal

fixed in #1089 ! :)

Helveg avatar Jul 07 '25 11:07 Helveg