How can I use CloudKit web services to query based on a reference field?

有些话、适合烂在心里 提交于 2019-12-12 10:48:32

问题


I've got two CloudKit data objects that look somewhat like this:

Parent Object:

{
    "records": [
        {
            "recordName": "14102C0A-60F2-4457-AC1C-601BC628BF47-184-000000012D225C57",
            "recordType": "ParentObject",
            "fields": {
                "fsYear": {
                    "value": "2015",
                    "type": "STRING"
                },
                "displayOrder": {
                    "value": 2015221153856287200,
                    "type": "INT64"
                },
                "fjpFSGuidForReference": {
                    "value": "14102C0A-60F2-4457-AC1C-601BC628BF47-184-000000012D225C57",
                    "type": "STRING"
                },
                "fsDateSearch": {
                    "value": "2015221153856287158",
                    "type": "STRING"
                },
            },
            "recordChangeTag": "id4w7ivn",
            "created": {
                "timestamp": 1439149087571,
                "userRecordName": "_0d26968032e31bbc72c213037b6cb35d",
                "deviceID": "A19CD995FDA3093781096AF5D818033A241D65C1BFC3D32EC6C5D6B3B4A9AA6B"
            },
            "modified": {
                "timestamp": 1439149087571,
                "userRecordName": "_0d26968032e31bbc72c213037b6cb35d",
                "deviceID": "A19CD995FDA3093781096AF5D818033A241D65C1BFC3D32EC6C5D6B3B4A9AA6B"
            }
        }
    ],
    "total": 
}

Child Object:

{
    "records": [
        {
            "recordName": "2015221153856287168",
            "recordType": "ChildObject",
            "fields": {
                "District": {
                    "value": "002",
                    "type": "STRING"
                },
                "ZipCode": {
                    "value": "12345",
                    "type": "STRING"
                },
                "InspecReference": {
                    "value": {
                        "recordName": "14102C0A-60F2-4457-AC1C-601BC628BF47-184-000000012D225C57",
                        "action": "NONE",
                        "zoneID": {
                            "zoneName": "_defaultZone"
                        }
                    },
                    "type": "REFERENCE"
                },
            },
            "recordChangeTag": "id4w7lew",
            "created": {
                "timestamp": 1439149090856,
                "userRecordName": "_0d26968032e31bbc72c213037b6cb35d",
                "deviceID": "A19CD995FDA3093781096AF5D818033A241D65C1BFC3D32EC6C5D6B3B4A9AA6B"
            },
            "modified": {
                "timestamp": 1439149090856,
                "userRecordName": "_0d26968032e31bbc72c213037b6cb35d",
                "deviceID": "A19CD995FDA3093781096AF5D818033A241D65C1BFC3D32EC6C5D6B3B4A9AA6B"
            }
        }
    ],
    "total": 1
}

I'm trying to write a query to directly access the CloudKit web service and return the Child Object based on the reference of the parent object.

My test JSON looks something like this:

{"query":{"recordType":"ChildObject","filterBy":{"fieldName":"InspecReference","fieldValue":{ "value" : "14102C0A-60F2-4457-AC1C-601BC628BF47-184-000000012D225C57", "type" : "string" },"comparator":"EQUALS"}},"zoneID":{"zoneName":"_defaultZone"}}

However, I'm getting the following error from CloudKit:

{"uuid":"33db91f3-b768-4a68-9056-216ecc033e9e","serverErrorCode":"BAD_REQUEST","reason":"BadRequestException: Unexpected input"}

I'm guessing I have the Record Field Dictionary in the query wrong. However, the documentation isn't clear on what this should look like on a reference object.


回答1:


You have to re-create the actual object of the reference. In this particular case, the JSON looks like this:

{
    "query": {
        "recordType": "ChildObject",
        "filterBy": {
            "fieldName": "InspecReference",
            "fieldValue": {
                "value": {
                    "recordName": "14102C0A-60F2-4457-AC1C-601BC628BF47-184-000000012D225C57",
                    "action": "NONE"
                },
                "type": "REFERENCE"
            },
            "comparator": "EQUALS"
        }
    },
    "zoneID": {
        "zoneName": "_defaultZone"
    }
}


来源:https://stackoverflow.com/questions/32751386/how-can-i-use-cloudkit-web-services-to-query-based-on-a-reference-field

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!