DomDew / strapi-plugin-fuzzy-search

Register a weighted fuzzy search endpoint for Strapi Headless CMS you can add your content types to in no time

Home Page:https://www.npmjs.com/package/strapi-plugin-fuzzy-search

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

ValidationError: Key: 'FIELDNAME' is not a valid field for model:

icsdevs opened this issue · comments

Got a strapi model with a component setup like this;

{
  "collectionName": "components_alloys_specifications",
  "info": {
    "displayName": "Specifications",
    "icon": "bulletList"
  },
  "options": {},
  "attributes": {
    "UNSNo": {
      "type": "string"
    },
    "WerkstoffNo": {
      "type": "string"
    },
    "ASTM": {
      "type": "string"
    },
    "AMS": {
      "type": "string"
    },
    "Other": {
      "type": "text"
    }
  }
}

This is called inside my model using this

"Specifications": {
      "displayName": "Specifications",
      "type": "component",
      "repeatable": false,
      "pluginOptions": {
        "i18n": {
          "localized": false
        }
      },
      "component": "alloys.specifications"
    },

and trying to define the 5 values as searchable element in fuzzysortOptions

fuzzysortOptions: {
                        characterLimit: 300,
                        threshold: -600,
                        limit: 10,
                        keys: [
                            {
                                name: "Title",
                                weight: 100,
                            },
                            {
                                name: "Content",
                                weight: -100,
                            },
                            {
                                name: "AboutContent",
                                weight: -100,
                            },
                            {
                                name: "ApplicationsContent",
                                weight: -100,
                            },
                            {
                                name: "UNSNo",
                                weight: -50
                            },
                            {
                                name: "WerkstoffNo",
                                weight: -50
                            },
                            {
                                name: "ASTM",
                                weight: -50
                            },
                            {
                                name: "AMS",
                                weight: -50
                            },
                            {
                                name: "Other",
                                weight: -50
                            }
                        ],
                    },
                },

but getting the following

0| [2024-05-29 10:34:15.823] error: Key: 'UNSNo' is not a valid field for model: 'alloy
0| ValidationError: Key: 'UNSNo' is not a valid field for model: 'alloy

This is on postgres

"dependencies": {
    "@strapi/plugin-i18n": "4.11.4",
    "@strapi/plugin-seo": "^1.9.2",
    "@strapi/plugin-users-permissions": "4.11.4",
    "@strapi/provider-upload-aws-s3": "^4.20.0",
    "@strapi/provider-upload-local": "^4.11.4",
    "@strapi/strapi": "4.11.4",
    "mysql": "^2.18.1",
    "pg": "^8.11.3",
    "sqlite3": "^5.1.7",
    "strapi-plugin-fuzzy-search": "^2.0.5",
    "strapi-plugin-menus": "^1.4.3",
    "strapi-plugin-navigation": "^2.4.0",
    "strapi-plugin-preview-button": "^1.1.3"
},

i have tried a few different things, but not sure how i'm meant to target these fields.

Hey hey @icsdevs ,
your model needs additional info, as we are validating against the pluralName and thus the available attributes/keys of the model, as these are used to fetch the entities from the db through strapi internals.

Something like this:

...
"info": {
    "singularName": "author",
    "pluralName": "authors",
    "displayName": "author",
    "description": ""
  },
...

These should be generated automatically if you configure your model through Strapi.

Thanks @DomDew ill review the model today and see how i get on.