【发布时间】:2019-04-05 15:09:47
【问题描述】:
我有这个模型
import {Entity, model, property} from '@loopback/repository';
@model()
export class Coupon extends Entity {
@property({
id: true,
type: 'string',
required: false,
mongo: {
columnName: '_id',
dataType: 'ObjectID',
},
})
id: string;
@property({
type: 'string',
required: true,
})
name: string;
@property({
type: 'number',
required: true,
})
maximumUses: number;
@property({
type: 'string',
required: true,
})
type: string;
@property({
type: 'number',
required: true,
})
amount: number;
@property({
type: 'number',
required: true,
})
maximumUsesPerPerson: number;
@property({
type: 'string',
required: true,
})
validFrom: string;
@property({
type: 'string',
required: true,
})
validTo: string;
@property({
type: 'number',
required: true,
})
currentTotalUses: number;
@property({
type: 'array',
itemType: 'string',
})
certainDays?: string[];
@property({
type: 'array',
itemType: 'string',
})
certainHours?: string[];
@property({
type: 'boolean',
required: true,
})
valid: boolean;
@property({
type: 'array',
itemType: 'string',
})
clients?: string[];
@property({
type: 'disabled',
required: true,
})
disabled: boolean;
constructor(data?: Partial<Coupon>) {
super(data);
}
}
模型库
import {DefaultCrudRepository} from '@loopback/repository';
import {Coupon} from '../models';
import {TestDataSource} from '../datasources';
import {inject} from '@loopback/core';
export class CouponRepository extends DefaultCrudRepository<
Coupon,
typeof Coupon.prototype.id
> {
constructor(
@inject('datasources.test') dataSource: TestDataSource,
) {
super(Coupon, dataSource);
}
}
现在下面的函数应该可以正常工作了
await this.couponsRepo.create({ name: 'string',
maximumUses: 0,
maximumUsesPerPerson: 0,
amount: 0,
validFrom: 'string',
validTo: 'string',
type: 'percentage',
valid: true,
currentTotalUses: 0,
disabled: false });
但它会触发此错误
ReferenceError: g 未定义 在新禁用时(在 createModelClassCtor 进行评估 (../LBIssue/lbissue/node_modules/loopback-datasource-juggler/lib/model-builder.js:678:21),:10:27)
为了简单地产生这个错误,创建空的 loopback 4 项目 然后将优惠券模型=与我提供的代码一起放入
【问题讨论】:
标签: node.js crud loopback v4l2loopback