I'm trying to query some records which should be filtered by a given reference.
When I simply hack the reference as value for the filter, this leads to an error.
var query = { recordType: 'Colors',
filterBy: [{
fieldName: 'User',
comparator: 'EQUALS',
fieldValue: { value: id }
}]};The given error looks fine, saying it's impossible to provide a string when a reference is needed.
{
"uuid":"c6b24310-f3e7-4f57-adc5-2411c3ed5a55",
"serverErrorCode":"BAD_REQUEST",
"reason":"BadRequestException: Invalid value, expected type REFERENCE but actual value was object of class java.lang.String"
}But when I construct a 'reference type' JSON object according to the CloudKit Web Services Reference, it doesn't work either.
var query = { recordType: 'Colors',
filterBy: [{
fieldName: 'User',
comparator: 'EQUALS',
fieldValue: { value: { recordName:representation.id, action:'NONE', zoneID:'_defaultZone' }, type: 'REFERENCE' }
}]};Now the response is just an internal server error without further information:
{
"uuid":"9b066fe8-5f4d-4856-a8f3-dda652a78399",
"serverErrorCode":"INTERNAL_ERROR"
}Building the query with a reference type instead of the value leads to the same result, so my guess is that the filter is in the wrong format.
Unfortunately neither the CloudKit Catalog nor the CloudKit JS documentation show how to build a query filtered by reference.
Since a reference is the recommended way to handle To–Many–Relations I cannot believe this query feature isn't implemented yet.
So how do I build a query in CloudKit JS which filters by a field containing a reference?