给出一个简单的Foo
实体,其中包含mongodb中的Bar
对象的集合
仅当列是数组和嵌入对象时才会出现问题。
@Entity()
export class Foo {
@ObjectIdColumn()
public id: ObjectID;
@Column()
public simple: string;
@Column(type => Bar)
public collection: Bar[];
}
export class Bar {
@Column()
value: boolean;
}
repository.create
改变了原始价值
{
"simple": "string",
"collection": [
{ "value": true },
{ "value": false }
]
}
简单地说
{ "simple": "string" }
我刚刚从https://github.com/typeorm/typeorm/issues/2342拿走了这个,但同样的事情发生在我的最后
显然,这是一种类型的bug。作为解决方法,您可以手动设置集合,直到问题得到解决:
async createFoo(createFooDto) {
const newFoo = await this.repository.create(createFooDto);
// TODO: Remove when https://github.com/typeorm/typeorm/issues/1980 is solved
newFoo.collection = createFooDto.collection;
this.repository.save(newFoo);
}
如果这是一个回归(它曾经工作),你可以尝试降级typeorm直到它被修复。