I have just notice that when i create a string field 'slug' like this:
fields: [
{
name: 'slug',
type: 'text',
unique: true,
localized: true,
index: true,
admin: {
readOnly: true,
position: 'sidebar',
},
hooks: {
beforeValidate: [
({ req: { payload }, data }) => {
if (payload) {
return slugify(data.name, {lower: true})
}
},
],
},
},
...
with the localized:true option,
and execute a find query:
let scrapped_brands = await payload.find({
collection: "brands",
where: {slug: { equals: 'slug1'}},
});
the query returns no results even when there are actually results in the database.
after some investigation i have noticed that the buildQuery function doesnt build the query correctly.
on document 'node_modules/payload/dist/mongoose/buildQuery.js'
the query that was created is:
{ 'slug.null': { '$eq': 'apple' } }
when removing the
{localized: true}
option and build again, then i gets the documents as expected and the buildQuery shows a correct query like this:
{ slug: { '$eq': 'apple' } }
not sure if this is a bug, but i wasted few hours on this one 😦
Hey @megetron if you're querying on a localized collection, you need to specify the locale in your query. There are examples of how to do this with the local / rest API here
https://payloadcms.com/docs/configuration/localization#retrieving-localized-docsAlso, did you enable localization project wide? You can find the info about that at the top of the docs page Jess sent over
didn't want to use the localization at all, so this issue was a mis-use of payload.
maybe it was helpful to add a short warning message that says that the localize was not found instead of just retreive the 'slug.null' value.
Star
Discord
online
Get help straight from the Payload team with an Enterprise License.