I’m writing a plugin that does some work on the current record and its related records. For that I want to use
await recordRepo.findOne({
filterByTk: currentRecord.id,
appends: ['relationship1'],
})
I want to be load only some records from relationship1, not all of them, based on some criteria. Reading the appends parsing code I think I should be able to use something like (relatedAttribute=val1), i.e.
await recordRepo.findOne({
filterByTk: currentRecord.id,
appends: ['relationship1(relatedAttribute=val1)'],
})
This however doesn’t work.
Is there some documentation on appends filters?
Specifically, I need to be able to filter with the IN operator, something like
await recordRepo.findOne({
filterByTk: currentRecord.id,
appends: ['relationship1(relatedAttribute[in]="val1", "val2")']
})
Note that val1 and val2 are strings.
Please try
await recordRepo.findOne({
filter: {
id: 1,
'<relationship1>.<relatedAtribute>': {
'$includes': ['val1', 'val2']
}
}
});
Thanks, this didn’t work. It generated 2 SQLs:
SELECT "parent_table"."id"
FROM "public"."parent_table" AS "parent_table"
LEFT OUTER JOIN "public"."related_table" AS "related_table" ON "parent_table"."id" = "related_table"."parent_fk"
WHERE "parent_table"."id" = 1
AND (
CAST("related_table"."related_attribute" AS TEXT) ILIKE '%val1%' OR
CAST("related_table"."related_attribute" AS TEXT) ILIKE '%val2%'
)
GROUP BY "parent_table"."id"
ORDER BY "parent_table"."id" ASC NULLS LAST
LIMIT 1;
and
SELECT "createdAt", "updatedAt", "id", <other fields>, "createdById", "updatedById"
FROM "public"."parent_table" AS "parent_table"
WHERE "parent_table"."id" IN (NULL)
ORDER BY "parent_table"."id" ASC NULLS LAST;
First, $include and $in are not quite the same - $include generates ILIKE conditions, whereas I need IN conditions.
Also, this filter really means "find record from parent_table where id = 1 and there is at least 1 record in relatedTable where relatedAttribute is in ‘val1’, ‘val2’.