如何在lb4发现中控制主键创建

问题描述

如何控制lb4 discover中ID(主键)的创建?

每当我呼叫lb4 discover时,它都会设置required: trueid: number,因此我必须将它们手动修改为所有可用主键的required: falseid?: 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)
);

lb4 discover生成

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 -------------------------------------------------------------------------------- 中存在一个错误

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...