问题描述
如何控制lb4 discover
中ID(主键)的创建?
每当我呼叫lb4 discover
时,它都会设置required: true
和id: number
,因此我必须将它们手动修改为所有可用主键的required: false
和id?: number
。是一件很烦人的事(我有一个庞大的数据库)
这个问题的一个小例子:
CREATE TABLE public.lists (
id serial NOT NULL,title varchar NOT NULL,description text NULL,color int2 NULL,CONSTRAINT lists_pk PRIMARY KEY (id)
);
import {Entity,model,property} from '@loopback/repository';@model({
settings: {
idInjection: false,postgresql: {schema: 'public',table: 'lists'},},})
export class Lists extends Entity {
@property({
type: 'number',//required: true,//------------------- A STUPID PROPERTY
scale: 0,id: 1,postgresql: {
columnName: 'id',dataType: 'integer',dataLength: null,dataPrecision: null,dataScale: 0,nullable: 'NO',})
id?: number;
//id: number; //--------------------- A STUPID PROPERTY @property({
type: 'string',required: true,postgresql: {
columnName: 'title',dataType: 'character varying',dataScale: null,})
title: string; @property({
type: 'string',postgresql: {
columnName: 'description',dataType: 'text',nullable: 'YES',})
description?: string; @property({
type: 'number',scale: 0,postgresql: {
columnName: 'color',dataType: 'smallint',})
color?: number; // Define well-kNown properties here // Indexer property to allow additional data
// eslint-disable-next-line @typescript-eslint/no-explicit-any
[prop: string]: any; constructor(data?: Partial<Lists>) {
super(data);
}
}export interface ListsRelations {
// describe navigational properties here
}export type ListsWithRelations = Lists & ListsRelations;
解决方法
似乎here正确地提到了 length width output
2 1.2 0.15 4
3 1.2 0.15 5
--------------------------------------------------------------------------------
length width output
5 2.0 1.0 3
6 2.0 1.0 4
--------------------------------------------------------------------------------
中存在一个错误