From 3f8778450ed0d05f7ddf504d04a1771db7b55482 Mon Sep 17 00:00:00 2001 From: LookinGit Date: Sat, 28 May 2022 23:47:27 +0500 Subject: [PATCH] fix(SoftDeletes): fix where clause of query as undefined --- src/SoftDeletes/index.ts | 2 +- test/relations.spec.ts | 12 ++++++++---- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/SoftDeletes/index.ts b/src/SoftDeletes/index.ts index d54acd5..705cfd3 100644 --- a/src/SoftDeletes/index.ts +++ b/src/SoftDeletes/index.ts @@ -29,7 +29,7 @@ export function SoftDeletes> (supercl if (query['ignoreDeleted'] === false) { return } - const isGroupLimitQuery = query.toQuery().includes('adonis_group_limit_counter') + const isGroupLimitQuery = query.clone().toQuery().includes('adonis_group_limit_counter') const deletedAtColumn = query.model.$getColumn('deletedAt')?.columnName const queryIgnoreDeleted = isGroupLimitQuery ? query.knexQuery['_single'].table : query diff --git a/test/relations.spec.ts b/test/relations.spec.ts index c12d8fc..81fc54e 100644 --- a/test/relations.spec.ts +++ b/test/relations.spec.ts @@ -108,8 +108,6 @@ test.group('Relations', (group) => { } class Book extends MyBaseModel { - public static table = 'books' - @column() public name: string @@ -118,8 +116,6 @@ test.group('Relations', (group) => { } class Author extends MyBaseModel { - public static table = 'authors' - @column() public name: string @@ -161,6 +157,7 @@ test.group('Relations', (group) => { assert.lengthOf(books, 1) assert.lengthOf(books[0].authors, 1) + await book1.related('authors').detach() await Promise.all([Book.truncate(), Author.truncate()]) }) @@ -230,6 +227,13 @@ test.group('Relations', (group) => { assert.lengthOf(authorsLimit2[0].authors, 2) assert.lengthOf(authorsLimit2[1].authors, 2) + const authorsJohns = await Book.query() + .preload('authors', (authors) => authors.where('name', 'Mary')) + .paginate(1, 10) + + assert.lengthOf(authorsJohns, 2) + assert.lengthOf(authorsJohns[0].authors, 1) + await Promise.all([Book.truncate(), Author.truncate()]) }) })