Skip to content

Commit

Permalink
fix(SoftDeletes): fix where clause of query as undefined
Browse files Browse the repository at this point in the history
  • Loading branch information
LookinGit committed May 28, 2022
1 parent 46e791c commit 3f87784
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/SoftDeletes/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export function SoftDeletes<T extends NormalizeConstructor<LucidModel>> (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
Expand Down
12 changes: 8 additions & 4 deletions test/relations.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,6 @@ test.group('Relations', (group) => {
}

class Book extends MyBaseModel {
public static table = 'books'

@column()
public name: string

Expand All @@ -118,8 +116,6 @@ test.group('Relations', (group) => {
}

class Author extends MyBaseModel {
public static table = 'authors'

@column()
public name: string

Expand Down Expand Up @@ -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()])
})

Expand Down Expand Up @@ -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()])
})
})

0 comments on commit 3f87784

Please sign in to comment.