我有一个看起来像这样的模型:
import {Entity, PrimaryGeneratedColumn, Column, OneToOne, JoinColumn, OneToMany} from "typeorm";
@Entity()
export class Item {
@PrimaryGeneratedColumn()
id: number;
@Column()
@OneToOne(() => Image, {
cascade: true
})
image?: Image;
}
@Entity()
export class Image {
@PrimaryGeneratedColumn()
id: number;
@OneToOne(() => Item)
@JoinColumn()
item: Item;
@Column({
type: 'int',
})
width: number;
@Column({
type: 'int',
})
height: number;
}
在我的应用代码中,我会这样做:
import { getConnection } from 'typeorm';
const item = new Item();
item.image = new Image();
item.image.width = 1920;
item.image.height = 1080;
await getConnection().manager.save(item);
基于 this documentation,我预计这会起作用。但是我收到了一个错误:
<块引用>DataTypeNotSupportedError:“sqlite”数据库不支持“Item.image”中的数据类型“Image”。