Support filtering relationships by _id

This commit is contained in:
Sam Rose 2025-02-24 16:15:59 +00:00
parent 3517f8cbc1
commit a959a26d60
No known key found for this signature in database
2 changed files with 25 additions and 4 deletions

View File

@ -3553,6 +3553,28 @@ if (descriptions.length) {
limit: 1, limit: 1,
}).toContainExactly([row]) }).toContainExactly([row])
}) })
it("can filter by the related _id", async () => {
await expectSearch({
query: {
equal: { "rel._id": row.rel[0]._id },
},
}).toContainExactly([row])
await expectSearch({
query: {
equal: { "rel._id": row.rel[1]._id },
},
}).toContainExactly([row])
})
it("can filter by the related _id and find nothing", async () => {
await expectSearch({
query: {
equal: { "rel._id": "rel_none" },
},
}).toFindNothing()
})
}) })
!isInternal && !isInternal &&

View File

@ -69,7 +69,8 @@ export const getQueryableFields = async (
fromTables: string[], fromTables: string[],
opts?: { noRelationships?: boolean } opts?: { noRelationships?: boolean }
): Promise<string[]> => { ): Promise<string[]> => {
const result = [] // Querying by _id is always allowed, even if it's never part of the schema
const result = ["_id"]
for (const field of Object.keys(table.schema).filter( for (const field of Object.keys(table.schema).filter(
f => allowedFields.includes(f) && table.schema[f].visible !== false f => allowedFields.includes(f) && table.schema[f].visible !== false
)) { )) {
@ -113,9 +114,7 @@ export const getQueryableFields = async (
return result return result
} }
const result = [ const result = []
"_id", // Querying by _id is always allowed, even if it's never part of the schema
]
if (fields == null) { if (fields == null) {
fields = Object.keys(table.schema) fields = Object.keys(table.schema)