fix: regression of filterOptions using different transaction (#5450)
This commit is contained in:
@@ -354,12 +354,12 @@ const validateFilterOptions: Validate<
|
|||||||
falseCollections.push(collection)
|
falseCollections.push(collection)
|
||||||
}
|
}
|
||||||
|
|
||||||
// `req` omitted to prevent transaction errors from aborting the entire transaction
|
|
||||||
const result = await payload.find({
|
const result = await payload.find({
|
||||||
collection,
|
collection,
|
||||||
depth: 0,
|
depth: 0,
|
||||||
limit: 0,
|
limit: 0,
|
||||||
pagination: false,
|
pagination: false,
|
||||||
|
req,
|
||||||
where: findWhere,
|
where: findWhere,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import type { Payload } from 'payload'
|
import type { Payload } from 'payload'
|
||||||
|
import type { PayloadRequest } from 'payload/types'
|
||||||
|
|
||||||
import { randomBytes } from 'crypto'
|
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', () => {
|
describe('Polymorphic Relationships', () => {
|
||||||
it('should allow REST querying on polymorphic relationships', async () => {
|
it('should allow REST querying on polymorphic relationships', async () => {
|
||||||
const movie = await payload.create({
|
const movie = await payload.create({
|
||||||
|
|||||||
Reference in New Issue
Block a user