回送4-不能将前缀属性用作外键

时间:2019-05-15 18:30:20

标签: typescript loopbackjs json-ld

我正在使用Loopback 4驱动的API处理JSON-LD负载。以下内容使我可以毫无问题地从父级查询到子级,反之亦然:

// Inside Parent entity
@hasMany(() => Child, {keyTo: 'parentCode'})
'children': Child[];

// Inside Child entity
@belongsTo(() => Parent)
'parentCode': string;

但是,一旦我将定义为JSON-LD的前缀包括在内,则尝试调用/parents/{id}/child ...:

// Inside Parent entity
@hasMany(() => Child, {keyTo: 'foo:ParentCode'})
'children': Child[];

// Inside Child entity
@belongsTo(() => Parent)
'foo:ParentCode': string;

...我收到以下错误:

Unhandled error in GET /skilllevels/Z/majorgroups: 500 AqlError: Not a valid simple reference: result.noc:ParentSkillLevel                                                      
    at new AqlError (/home/max/git/esdc/noc-arangodb/node_modules/aqb/errors.js:5:13)
    at new SimpleReference (/home/max/git/esdc/noc-arangodb/node_modules/aqb/types.js:403:11)                                                                                   
    at Function.castString [as string] (/home/max/git/esdc/noc-arangodb/node_modules/aqb/types.js:64:10)                                                                        
    at Object.autoCastToken (/home/max/git/esdc/noc-arangodb/node_modules/aqb/types.js:88:29)                                                                                   
    at Function.QB.(anonymous function) [as eq] (/home/max/git/esdc/noc-arangodb/node_modules/aqb/index.js:43:13)                                                               
    at /home/max/git/esdc/noc-arangodb/node_modules/loopback-connector-arangodb/lib/arangodb.js:830:37                                                                          
    at ArangoDBConnector._buildWhere (/home/max/git/esdc/noc-arangodb/node_modules/loopback-connector-arangodb/lib/arangodb.js:836:9)                                           
    at ArangoDBConnector.all (/home/max/git/esdc/noc-arangodb/node_modules/loopback-connector-arangodb/lib/arangodb.js:868:22)                                                  
    at invokeConnectorMethod (/home/max/git/esdc/noc-arangodb/node_modules/loopback-datasource-juggler/lib/dao.js:172:21)                                                       
    at /home/max/git/esdc/noc-arangodb/node_modules/loopback-datasource-juggler/lib/dao.js:1712:7                                                                               
    at doNotify (/home/max/git/esdc/noc-arangodb/node_modules/loopback-datasource-juggler/lib/observer.js:156:49)                                                               
    at doNotify (/home/max/git/esdc/noc-arangodb/node_modules/loopback-datasource-juggler/lib/observer.js:156:49)                                                               
    at Function.ObserverMixin._notifyBaseObservers (/home/max/git/esdc/noc-arangodb/node_modules/loopback-datasource-juggler/lib/observer.js:179:5)                             
    at Function.ObserverMixin.notifyObserversOf (/home/max/git/esdc/noc-arangodb/node_modules/loopback-datasource-juggler/lib/observer.js:154:8)                                
    at Function.ObserverMixin._notifyBaseObservers (/home/max/git/esdc/noc-arangodb/node_modules/loopback-datasource-juggler/lib/observer.js:177:15)                            
    at Function.ObserverMixin.notifyObserversOf (/home/max/git/esdc/noc-arangodb/node_modules/loopback-datasource-juggler/lib/observer.js:154:8)

这似乎是由于属性名称中的冒号:引起的。我尝试设置关系名称。只要调整了子存储库,它就不会抛出错误,而是总是返回一个空数组:

// Inside Parent entity
@hasMany(() => Child, {keyTo: 'ParentCode'})
'children': Child[];

// Inside Child entity
@belongsTo(() => Parent, {name: 'ParentCode'})
'foo:ParentCode': string;

:或其他符号引起问题的其他情况下,我将使用Object['key']表示法。但是由于错误来自较低级别的框架,因此我不知道如何做到这一点。在保持:属性名称内的同时,有什么方法可以使关系正常工作?

0 个答案:

没有答案