Files
payload/test/joins/collections/Posts.ts
Dan Ribbens 93a55d1075 feat: add join field config where property (#8973)
### What?

Makes it possible to filter join documents using a `where` added
directly in the config.


### Why?

It makes the join field more powerful for adding contextual meaning to
the documents being returned. For example, maybe you have a
`requiresAction` field that you set and you can have a join that
automatically filters the documents to those that need attention.

### How?

In the database adapter, we merge the requested `where` to the `where`
defined on the field.
On the frontend the results are filtered using the `filterOptions`
property in the component.

Fixes
https://github.com/payloadcms/payload/discussions/8936
https://github.com/payloadcms/payload/discussions/8937

---------

Co-authored-by: Sasha <64744993+r1tsuu@users.noreply.github.com>
2024-11-06 10:06:25 -05:00

74 lines
1.5 KiB
TypeScript

import type { CollectionConfig } from 'payload'
import { categoriesSlug, postsSlug, uploadsSlug } from '../shared.js'
export const Posts: CollectionConfig = {
slug: postsSlug,
admin: {
useAsTitle: 'title',
defaultColumns: ['title', 'category', 'updatedAt', 'createdAt'],
},
fields: [
{
name: 'title',
type: 'text',
},
{
name: 'isFiltered',
type: 'checkbox',
defaultValue: false,
admin: {
position: 'sidebar',
description: 'Hides posts for the `filtered` join field in categories',
},
},
{
name: 'restrictedField',
type: 'text',
access: {
read: () => false,
update: () => false,
},
},
{
name: 'upload',
type: 'upload',
relationTo: uploadsSlug,
},
{
name: 'category',
type: 'relationship',
relationTo: categoriesSlug,
},
{
name: 'categories',
type: 'relationship',
relationTo: categoriesSlug,
hasMany: true,
},
{
name: 'categoriesLocalized',
type: 'relationship',
relationTo: categoriesSlug,
hasMany: true,
localized: true,
},
{
name: 'group',
type: 'group',
fields: [
{
name: 'category',
type: 'relationship',
relationTo: categoriesSlug,
},
{
name: 'camelCaseCategory',
type: 'relationship',
relationTo: categoriesSlug,
},
],
},
],
}