我想指定2个mssql表之间的关系.Paymentcategory和支付.paymentcategory.id加入payout.category列.
在payout.json模型中我指定为foreignKey:id,
"relations": {
"paymentcategories": {
"type": "hasOne",
"model": "Paymentcategory",
"foreignKey": "id"
}
Run Code Online (Sandbox Code Playgroud)
但是对于id字段,loopback默认为primaryKey
有没有办法在类别字段上指定连接.最好在common/models/payout.json文件中?
"relations": {
"paymentcategories": {
"type": "hasOne",
"model": "Paymentcategory",
"foreignKey": "id",
"primaryKey": "category" ??????????????????
}
Run Code Online (Sandbox Code Playgroud)
现在我收到这个错误:
"error": {
"name": "Error",
"status": 400,
"message": "Key mismatch: Paymentpayout.id: undefined, Paymentcategory.id: 1",
"statusCode": 400,
Run Code Online (Sandbox Code Playgroud) 我想知道为什么jest.useFakeTimers与setTimeoutRxJs的延迟运算符一起工作但不是:
jest.useFakeTimers();
import {Observable} from 'rxjs/Observable';
import 'rxjs';
describe('timers', () => {
it('should resolve setTimeout synchronously', () => {
const spy = jest.fn();
setTimeout(spy, 20);
expect(spy).not.toHaveBeenCalled();
jest.runTimersToTime(20);
expect(spy).toHaveBeenCalledTimes(1);
});
it('should resolve setInterval synchronously', () => {
const spy = jest.fn();
setInterval(spy, 20);
expect(spy).not.toHaveBeenCalled();
jest.runTimersToTime(20);
expect(spy).toHaveBeenCalledTimes(1);
jest.runTimersToTime(20);
expect(spy).toHaveBeenCalledTimes(2);
});
it('should work with observables', () => {
const delay$ = Observable.of(true).delay(20);
const spy = jest.fn();
delay$.subscribe(spy);
expect(spy).not.toHaveBeenCalled();
jest.runTimersToTime(2000);
expect(spy).toHaveBeenCalledTimes(1);
});
});
Run Code Online (Sandbox Code Playgroud)
仅供参考:使用20或2000作为参数jest.runTimersToTime没有任何区别.使用jest.runAllTimers()使测试过去