有了这个,我不理解它,我不想污染原始问题。我需要一直{ wrappedReference: true }
使用IdentifiedReference
吗?
因为,这失败了:
@Entity({ collection: "account" })
export class AccountEntity implements IdEntity<AccountEntity> {
@PrimaryKey()
public id!: number;
@OneToOne(() => ArtistEntity, "account", { wrappedReference: true })
public artist!: IdentifiedReference<ArtistEntity>;
}
@Entity({ collection: "artist" })
export class ArtistEntity implements IdEntity<ArtistEntity> {
@PrimaryKey()
public id!: number;
@OneToOne(() => AccountEntity, { wrappedReference: true })
public account!: IdentifiedReference<AccountEntity>;
}
和:
src/entities/artistEntity.ts(15,38): error TS2345: Argument of type '{ WrappedReference: boolean; }' 不能分配给“id”类型的参数 | “名字” | “密码” | “电子邮件” | “形象” | “艺术家” | “收藏” | “工作室” | ((e:AccountEntity)=>任何)| 不明确的'。对象字面量只能指定已知属性,并且类型“(e:AccountEntity)=> any”中不存在“wrappedReference”。
那么,这会正确吗?
@Entity({ collection: "account" })
export class AccountEntity implements IdEntity<AccountEntity> {
@PrimaryKey()
public id!: number;
@OneToOne(() => ArtistEntity, "account", { wrappedReference: true })
public artist!: IdentifiedReference<ArtistEntity>;
}
@Entity({ collection: "artist" })
export class ArtistEntity implements IdEntity<ArtistEntity> {
@PrimaryKey()
public id!: number;
@OneToOne(() => AccountEntity)
public account!: IdentifiedReference<AccountEntity>;
}