feat: join field defaultLimit and defaultSort (#8908)
### What?
Allow specifying the defaultSort and defaultLimit to use for populating
a join field
### Why?
It is much easier to set defaults rather than be forced to always call
the join query using the query pattern ("?joins[categories][limit]=0").
### How?
See docs and type changes
This commit is contained in:
@@ -47,7 +47,10 @@ export const Categories: CollectionConfig = {
|
||||
label: 'Related Posts',
|
||||
type: 'join',
|
||||
collection: postsSlug,
|
||||
defaultSort: '-title',
|
||||
defaultLimit: 5,
|
||||
on: 'category',
|
||||
maxDepth: 1,
|
||||
},
|
||||
{
|
||||
name: 'hasManyPosts',
|
||||
|
||||
@@ -105,15 +105,6 @@ describe('Joins Field', () => {
|
||||
},
|
||||
collection: 'categories',
|
||||
})
|
||||
// const sortCategoryWithPosts = await payload.findByID({
|
||||
// id: category.id,
|
||||
// joins: {
|
||||
// 'group.relatedPosts': {
|
||||
// sort: 'title',
|
||||
// },
|
||||
// },
|
||||
// collection: 'categories',
|
||||
// })
|
||||
|
||||
expect(categoryWithPosts.group.relatedPosts.docs).toHaveLength(10)
|
||||
expect(categoryWithPosts.group.relatedPosts.docs[0]).toHaveProperty('id')
|
||||
@@ -125,11 +116,12 @@ describe('Joins Field', () => {
|
||||
const { docs } = await payload.find({
|
||||
limit: 1,
|
||||
collection: 'posts',
|
||||
depth: 2,
|
||||
})
|
||||
|
||||
expect(docs[0].category.id).toBeDefined()
|
||||
expect(docs[0].category.name).toBeDefined()
|
||||
expect(docs[0].category.relatedPosts.docs).toHaveLength(10)
|
||||
expect(docs[0].category.relatedPosts.docs).toHaveLength(5) // uses defaultLimit
|
||||
})
|
||||
|
||||
it('should populate relationships in joins with camelCase names', async () => {
|
||||
|
||||
Reference in New Issue
Block a user