Skip to content

Use the "where" clause to filter records with empty parents #843

Closed Answered by pedramardakani
pedramardakani asked this question in Q&A
Discussion options

You must be logged in to vote

Oh I just found the culprit. The where clause must use IsNull() function imported from typeorm:

// truncated
import { IsNull, Repository } from 'typeorm'; // 🫲 Import IsNull
// truncated
  static readonly PAGINATION_CONFIG: PaginateConfig<Category> = {
    where: { parent: IsNull() }, // 🫲 here's the solution
    sortableColumns: ['name', 'subcategories.name'],
    searchableColumns: ['name', 'subcategories.name'],
    nullSort: 'last',
    defaultSortBy: [['name', 'DESC']],
    relations: ['subcategories'],
    maxLimit: 0,
    filterableColumns: {
      name: [FilterOperator.ILIKE],
      'subcategories.name': [FilterOperator.ILIKE],
    },
  };

  async findAll(query: PaginateQuery) {

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by pedramardakani
# for free to join this conversation on GitHub. Already have an account? # to comment
Category
Q&A
Labels
None yet
1 participant