Return softDeleted relation rows

I have a table called “bsService” where I save my created services, that services have some relations like, categories, activities and others. I’m trying to get services where categories was softDeleted, example: service 1 relates to category 1, then I softDeleted category 1, now this service don’t return on findAll even if add ‘withDeleted: true’ on the query.

Here’s my findAll method. The thing is that I want all data even if a relation is softDeleted.

findAll = async (
    where?: WhereConditions,
    transactionEntityManager: EntityManager = getManager(),
    order?: 'ASC' | 'DESC',
    withDeleted?: boolean,
  ): Promise<BSService[]> => transactionEntityManager.find(BSService, {
    withDeleted,
    where,
    relations: ['sla', 'activity', 'activity.category', 'department', 'department.company', 'attendance', 'logs', 'logs.user', 'requestingAgent', 'alocatedAgent', 'category', 'requestingAgent.jobs', 'alocatedAgent.jobs'],
    order: {
      updateAt: order,
    },
  });

The ‘withDeleted’ cames true depending on which page client is using, for that example is always true.

Thanks for the answers!

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

withDeleted in .find() only applies to the top layer, not relations.

Here’s someone with a similar issue.

Here’s a PR that shows how you can solve it by using a query builder with .withDeleted() before the relations you want to include. There’s some discussion about supporting this with .find() but it seems like it won’t be any time soon.

await manager
  .getRepository(BSService)
  .createQueryBuilder('bsservice')
  .withDeleted() // Above innerJoinAndSelects
  .innerJoinAndSelect('bsservice.sla', 'sla')
  .innerJoinAndSelect('bsservice.activity', 'activity')
  // ... more inner joins ...
  .getMany();


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x