Compare commits

...

1 Commits

Author SHA1 Message Date
Jessica Chowdhury
8adc2825f4 chore: reproduce bug in joins test suite 2024-10-28 13:58:50 -04:00
6 changed files with 121 additions and 24 deletions

View File

@@ -99,9 +99,9 @@ export const buildJoinAggregation = async ({
{
$lookup: {
as: `${as}.docs`,
foreignField: `${join.field.on}${code}`,
// foreignField: `${join.field.on}${code}`,
from: slug,
localField: versions ? 'parent' : '_id',
// localField: versions ? 'parent' : '_id',
pipeline,
},
},
@@ -140,9 +140,9 @@ export const buildJoinAggregation = async ({
{
$lookup: {
as: `${as}.docs`,
foreignField: `${join.field.on}${localeSuffix}`,
// foreignField: `${join.field.on}${localeSuffix}`,
from: slug,
localField: versions ? 'parent' : '_id',
// localField: versions ? 'parent' : '_id',
pipeline,
},
},

View File

@@ -0,0 +1,21 @@
import { joinDocsSlug } from '../shared.js'
export const JoinDocs: any = {
slug: joinDocsSlug,
admin: {
useAsTitle: 'title',
description: 'A collection with a join to relating collection',
},
fields: [
{
name: 'title',
type: 'text',
},
{
name: 'relationship',
type: 'join',
collection: 'relationship-docs',
on: 'relationship',
},
],
}

View File

@@ -0,0 +1,29 @@
import { postsSlug, relationshipDocsSlug } from '../shared.js'
export const RelationshipDocs: any = {
slug: relationshipDocsSlug,
admin: {
useAsTitle: 'title',
description: 'A collection with a relationship to a collection with a join field',
},
fields: [
{
name: 'title',
type: 'text',
},
{
name: 'joinRelationship',
type: 'relationship',
relationTo: 'join-docs',
description: 'Relationship field to a collection with a join field',
},
{
name: 'relationship',
type: 'relationship',
relationTo: postsSlug,
admin: {
description: 'Normal relationship field for comparison',
},
},
],
}

View File

@@ -4,7 +4,9 @@ import path from 'path'
import { buildConfigWithDefaults } from '../buildConfigWithDefaults.js'
import { Categories } from './collections/Categories.js'
import { CategoriesVersions } from './collections/CategoriesVersions.js'
import { JoinDocs } from './collections/Joins.js'
import { Posts } from './collections/Posts.js'
import { RelationshipDocs } from './collections/Relationship.js'
import { Uploads } from './collections/Uploads.js'
import { Versions } from './collections/Versions.js'
import { seed } from './seed.js'
@@ -20,6 +22,8 @@ export default buildConfigWithDefaults({
Uploads,
Versions,
CategoriesVersions,
RelationshipDocs,
JoinDocs,
{
slug: localizedPostsSlug,
admin: {

View File

@@ -6,7 +6,14 @@ import { fileURLToPath } from 'url'
import { devUser } from '../credentials.js'
import { seedDB } from '../helpers/seed.js'
import { categoriesSlug, collectionSlugs, postsSlug, uploadsSlug } from './shared.js'
import {
categoriesSlug,
collectionSlugs,
joinDocsSlug,
postsSlug,
relationshipDocsSlug,
uploadsSlug,
} from './shared.js'
const filename = fileURLToPath(import.meta.url)
const dirname = path.dirname(filename)
@@ -28,36 +35,66 @@ export const seed = async (_payload) => {
},
})
await _payload.create({
collection: postsSlug,
// await _payload.create({
// collection: postsSlug,
// data: {
// category: category.id,
// group: {
// category: category.id,
// },
// title: 'Test Post 1',
// },
// })
// await _payload.create({
// collection: postsSlug,
// data: {
// category: category.id,
// group: {
// category: category.id,
// },
// title: 'Test Post 2',
// },
// })
// await _payload.create({
// collection: postsSlug,
// data: {
// category: category.id,
// group: {
// category: category.id,
// },
// title: 'Test Post 3',
// },
// })
const { id: joinID1 } = await _payload.create({
collection: joinDocsSlug,
data: {
category: category.id,
group: {
category: category.id,
},
title: 'Test Post 1',
title: '1',
},
})
const { id: joinID2 } = await _payload.create({
collection: joinDocsSlug,
data: {
title: '2',
},
})
await _payload.create({
collection: postsSlug,
collection: relationshipDocsSlug,
data: {
category: category.id,
group: {
category: category.id,
},
title: 'Test Post 2',
title: '1',
joinRelationship: joinID1,
},
})
await _payload.create({
collection: postsSlug,
collection: relationshipDocsSlug,
data: {
category: category.id,
group: {
category: category.id,
},
title: 'Test Post 3',
title: '2',
joinRelationship: joinID2,
},
})

View File

@@ -8,9 +8,15 @@ export const localizedPostsSlug = 'localized-posts'
export const localizedCategoriesSlug = 'localized-categories'
export const relationshipDocsSlug = 'relationship-docs'
export const joinDocsSlug = 'join-docs'
export const collectionSlugs = [
categoriesSlug,
postsSlug,
localizedPostsSlug,
localizedCategoriesSlug,
relationshipDocsSlug,
joinDocsSlug,
]