0

插入新记录后,我意识到对象中的所有公式属性都是空的。

这是一个实体:

@Entity()
export class Book extends BaseEntity {

  @Property()
  title: string;

  @Property()
  width: number;

  @Property()
  height: number;

  @Formula('width * height')
  area?: number;

  constructor(title: string, width: number, height: number) {
    this.title = title;
    this.width = width;
    this.height = height;
  }
}

我现在正在做的是findOne在用refresh: true.

const book = new Book('test', 15, 20);
em.persist(book);
await em.flush();
await em.findOne({ id: book.id }, { refresh: true });

这是最好的方法还是有其他更直接的方法?

我在文档中找不到对此的任何引用。

4

0 回答 0