fix: regression of filterOptions using different transaction (#5450)

This commit is contained in:
Dan Ribbens
2024-03-26 10:13:57 -04:00
committed by GitHub
parent 92ff896bdb
commit 0ce752af79
2 changed files with 31 additions and 1 deletions

View File

@@ -354,12 +354,12 @@ const validateFilterOptions: Validate<
falseCollections.push(collection)
}
// `req` omitted to prevent transaction errors from aborting the entire transaction
const result = await payload.find({
collection,
depth: 0,
limit: 0,
pagination: false,
req,
where: findWhere,
})

View File

@@ -1,4 +1,5 @@
import type { Payload } from 'payload'
import type { PayloadRequest } from 'payload/types'
import { randomBytes } from 'crypto'
@@ -689,6 +690,35 @@ describe('Relationships', () => {
})
})
describe('Creating', () => {
describe('With transactions', () => {
it('should be able to create filtered relations within a transaction', async () => {
const req = {} as PayloadRequest
req.transactionID = await payload.db.beginTransaction?.()
const related = await payload.create({
collection: relationSlug,
data: {
name: 'parent',
},
req,
})
const withRelation = await payload.create({
collection: slug,
data: {
filteredRelation: related.id,
},
req,
})
if (req.transactionID) {
await payload.db.commitTransaction?.(req.transactionID)
}
expect(withRelation.filteredRelation.id).toEqual(related.id)
})
})
})
describe('Polymorphic Relationships', () => {
it('should allow REST querying on polymorphic relationships', async () => {
const movie = await payload.create({