Simplify your stack and build anything. Or everything.
Build tomorrow’s web with a modern solution you truly own.
Code-based nature means you can build on top of it to power anything.
It’s time to take back your content infrastructure.

relationship hasMany fails with more than 10 items

default discord avatar
grandnainconnu3 years ago
8

Relationship (many) field with no max/min defined fails with more than 10 items. Setting a "max" doesn't change the outcome.



Any solution on that?

  • discord user avatar
    denolfe
    3 years ago

    This doesn't sound like normal behavior. Can you expand upon what you're seeing? What is the failure?

  • default discord avatar
    grandnainconnu3 years ago

    Here is the code:


    {
              label: { fr: "Accessoires", en: "Accessories" },
              fields: [
                {
                  name: "accessories",
                  label: {
                    en: "Accessories",
                    fr: "Accessoires",
                  },
                  type: "relationship",
                  relationTo: "products",
                  hasMany: true,
                  filterOptions: ({ data }) => {
                    const typedData = data as Product;
    
                    return {
                      and: [
                        {
                          brand: {
                            equals: typedData.brand,
                          },
                        },
                        {
                          isBrandAccessory: {
                            equals: true,
                          },
                        },
                      ],
                    };
                  },
                },
              ],
            },


    Here is the error:



    [2023-06-02T15:37:11]
    [15:37:11] ERROR (payload): ValidationError: Le champ suivant n'est pas valide : accessories
    [2023-06-02T15:37:11]
    at beforeChange (/workspace/node_modules/payload/dist/fields/hooks/beforeChange/index.js:31:15)
    [2023-06-02T15:37:11]
    at runMicrotasks (<anonymous>)
    [2023-06-02T15:37:11]
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    [2023-06-02T15:37:11]
    at async updateByID (/workspace/node_modules/payload/dist/collections/operations/updateByID.js:143:18)
    [2023-06-02T15:37:11]
    at async updateByIDHandler (/workspace/node_modules/payload/dist/collections/requestHandlers/updateByID.js:19:21)
    [2023-06-02T14:38:20]
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    [2023-06-02T14:38:20]
    at async updateByID (/workspace/node_modules/payload/dist/collections/operations/updateByID.js:143:18)
    [2023-06-02T14:38:20]
    at async updateByIDHandler (/workspace/node_modules/payload/dist/collections/requestHandlers/updateByID.js:19:21)


    I have no custom hooks installed on this collection though, and the relationship is self referencing

  • discord user avatar
    jacobsfletch
    3 years ago

    So it throws a validation error when you select more than 10 relationships?

  • default discord avatar
    grandnainconnu3 years ago

    Yes exactly, but I can’t identify why

  • discord user avatar
    jacobsfletch
    3 years ago

    Interesting, if you can create a minimally reproducible config, this would help narrow down any potential bugs. For instance, remove the self-reference and

    filterOptions

    to see if the issue persists. If so let’s open a ticket on GitHub. There’s a

    tests/_community

    folder in the repo for this exact purpose, if needed.

  • default discord avatar
    grandnainconnu2 years ago

    (sorry for the delay)



    https://codesandbox.io/p/sandbox/cranky-chebyshev-rkppjr

    @808734492645785600

    here you go for the sandbox.


    The source of the problem is the

    filterOptions

    method.



    You can go to

    Examples

    ->

    The main test

    It has now 10 associations, if you add one more, the bug appears.



    I forgot that the content is not kept between session. I'll create a seeding option



    https://github.com/payloadcms/payload/issues/2860

    I made the issue with the reproduction steps

  • discord user avatar
    jacobsfletch
    2 years ago

    This is great, thank you!!



    We’re on it

  • default discord avatar
    grandnainconnu2 years ago

    Thanks!

Star on GitHub

Star

Chat on Discord

Discord

online

Can't find what you're looking for?

Get dedicated engineering support directly from the Payload team.