I currently have a collection of 'equipment', which has a relationship field to a nestedDocs collection called 'equipment-categories'.
I have just seeded about 200 equipment docs into the collection via a script which went OK.
My issue now is that when I type a category into the field to find/filter categories, I'm not seeing newly created ones, or in some occasions ones that exist as a result of the import script. Further more, it's seems random, if I refresh the page, I MIGHT get to see a category or I might not.
If I search for a newly created category "most popular" (slug: "most-popular") in an equipment document in the admin, I'm not getting any network errors in the browser as I type for, but the response comes back with docs [], but totalDocs 1. See pictures.
Really at a loss if anyone could please help me out!
I experience this issue if I'm running local dev, or in production.
this is my categories collection config
const payload = require('payload');
import type { CollectionConfig } from 'payload/types';
import slugify from 'slugify';
export const EquipmentCategories: CollectionConfig = {
slug: 'equipment-categories',
labels: {
singular: 'Equipment Category',
plural: 'Equipment Categories',
},
admin: {
useAsTitle: 'title',
hideAPIURL: true,
},
access: {
read: () => true,
},
fields: [
{
name: 'title',
label: 'Title',
type: 'text',
required: true,
index: true,
hooks: {
beforeChange: [
({ req: { payload }, data }) => {
if (payload) {
return data.title.toLowerCase();
}
},
],
},
},
{
name: 'categoryCount',
type: 'number',
admin: {
readOnly: true,
},
hooks: {
beforeChange: [
({ siblingData }) => {
siblingData.categoryCount = undefined;
},
],
afterRead: [
async ({ req, data }) => {
const docQuery = await payload.find({
collection: 'equipment',
where: {
categories: { equals: data.id },
},
depth: 0,
limit: 0,
});
if (docQuery?.docs) {
return docQuery?.totalDocs;
}
return 0;
},
],
},
},
{
name: 'slug',
type: 'text',
unique: true,
index: true,
admin: {
position: 'sidebar',
readOnly: true,
},
hooks: {
beforeValidate: [
({ req: { payload }, data }) => {
if (payload) {
if (data._status === 'draft') {
return;
}
return slugify(data.title, { lower: true });
}
},
],
},
},
],
};
My equipment collection config is about three metric miles long, but here's a snippet:
{
type: 'tabs',
tabs: [
{
label: 'Details',
fields: [
{
index: true,
name: 'name',
type: 'text',
required: true,
},
{
index: true,
name: 'categories',
type: 'relationship',
relationTo: 'equipment-categories',
hasMany: true,
required: true,
},
{
index: true,
name: 'subtitle',
type: 'text',
},
{
index: true,
name: 'synonyms',
type: 'text',
},
{
name: 'description',
label: 'Product Description',
type: 'richText',
admin: {
elements: [
'h3',
'h4',
'link',
'ol',
'ul',
'indent',
'blockquote',
],
leaves: ['bold', 'italic', 'underline', 'strikethrough'],
},
},
{
type: 'group',
name: 'additionalInfo',
fields: [
{
name: 'ppe',
type: 'relationship',
label: 'Required PPE',
relationTo: 'ppe',
hasMany: true,
},
{
name: 'transportOptions',
type: 'relationship',
relationTo: 'transport-options',
hasMany: true,
},
{
name: 'equipmentDocuments',
type: 'relationship',
relationTo: 'equipment-documents',
hasMany: true,
The "most popular" category database items doesn't appear to be any different to a category that I can repeatidly show up in the field
If i refresh the admin ui editor page, and quickly type into the category field, say within 200ms I can get the category to show up.
I also just added a test collection with a title and a relationship to the same equipment-catgories, and I experience the same issue.
Oh I'm narrowing in on a thing
I just spun up another payload dev environment with a minimal config. I copied accross my equipment collection, my equipment categories collection, the nested docs plugin, and I exported the equipment-categories collection from Atlas and imported them into my test environment and everything worked as expected.
Just checked the version numbers and my test Payload was 1.7.5 and my production site is running 1.9.0
Ok. v1.8.6 break the things.
@dribbens I think in release 1.8.6 something was introduced that breaks the admin ui field sorting/filtering for a relationship field. I'm unsure if it's related to the nestedDocs plugin or not. Sorry to tag you in this, but I thought it might be of some interest to you.
Happy to share more details or a repo if required.
Yes, if it's reproducible we need to address this. @_itsjustchris
We try and do all our bugfixes Monday so if you can get an issue in now we can handle it ASAP
@_itsjustchris if you open the request in a new tab (right click on request, open in new tab), BUT change the page=5 parameter to page=1, does the doc come back? I suspect that is the underlying bug
@jarrod_not_jared you nailed it, that's returning the expected docs
@dribbens Sorry for the late reply, New Zealand is a few hours ahead, i'll make up an issue now. It will be my first one, so forgive me if it seems weird.
I am running into the same issue. I don't see an issue for this bug, is it already fixed or should i create one?
I don't think an issue was ever created
ok, don't have a solid way to reproduce the issue yet, only happens when there is a lot of content.
I am wondering if @_itsjustchris could throw together one since he has a seed script written already for his project
That would be much easier indeed.
I’ll do my best to get something up tonight. Unfortunately I’m in that magical last 5% of kicking a project out the door and am swamped with bugs.
@harleyqueens I think you are experiencing what @mvdve have been. I've had no success so far getting it reproduced in my test environment - mostly due to lack of time. If someone wanted to make up an issue, i'd be happy to share a repo with my seed script etc to get you started.
I have noticed that the where query shows
where[and][1][title][like]:
What does the and 1 do? And shoudn't it be
ilike
instead of the
like
query?
Update: If I omit the
[and][1]
, (manually) get results from the request
https://github.com/payloadcms/payload/blob/master/src/admin/components/forms/field-types/Relationship/index.tsx#L137-L145
I will try to create a project which reproduces the issue, have a import script somewhere which i can refactor to a seeder.
Got it, repo on the way
Experiencing the same problem here, after updating from 1.7.4 to 1.9.5
It was introduced in 1.8.6, you could rollback to 1.8.4 to fix it for now
https://github.com/payloadcms/payload/issues/2859
for a repo to reproduce the problem
Thank you!
I'm working on a fix now and planning to have a new release today.
This was fixed in v1.10.0
Outstanding. Thank you Dan
Star
Discord
online
Get help straight from the Payload team with an Enterprise License.