Nested Relational Query Returns Empty Arrays (Including Admin Panel Filtering) #9852
-
Hi everyone I encountered an issue where querying nested relational properties returns an empty array. This previously worked in earlier versions: Before update
After update (issue encountered)
Additional environment info
Code ExampleFunction: Query apartments filtered by a relational location's slug field. export const getApartmentBySlug = async (
locationSlug: string,
options?: { locale?: string; draft?: boolean },
) => {
const payload = await getPayload({ config });
console.log(`Fetching apartments for location: ${locationSlug}`);
const { docs: apartments } = await payload.find({
collection: "apartments",
where: {
"location.slug": {
equals: locationSlug,
},
},
depth: 2,
locale: validateLocale(options?.locale),
limit: 1000,
sort: "priority",
});
console.log("Apartments:", apartments);
return apartments;
}; Expected Behavior:The function should return all apartments where location.slug matches the locationSlug parameter. Current Behavior:The docs array is empty ([]), even though apartments with the specified location.slug exist in the database. Admin Panel Issue:When trying to filter apartments by the location relation in the admin panel, no results are returned. Steps to Reproduce1. Schema:
2.Run Query:
3. Observe Behavior:
AppendixBefore update ✅Console:
Admin Panel:Admin Panel after location filter applied: ✅After update (issue encountered) ❌Console:
Admin Panel:Admin Panel after location filter applied: ❌Data entry in database |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Solution is found here: Quoting Eustachio: "I have found the answer for this, basically relationship id has to be ObjectId. From Payload V2 the relationship field (non-polymorphic) to websites was a string and in Payload V3 it is an ObjectId, once I went to each document where the websites relationship was and saved it, the field turned into an ObjectId and all the queries worked back again." |
Beta Was this translation helpful? Give feedback.
Solution is found here:
https://discord.com/channels/967097582721572934/1324460994906558504/1326256604819226624
Quoting Eustachio: "I have found the answer for this, basically relationship id has to be ObjectId. From Payload V2 the relationship field (non-polymorphic) to websites was a string and in Payload V3 it is an ObjectId, once I went to each document where the websites relationship was and saved it, the field turned into an ObjectId and all the queries worked back again."