如何解决Mikro-orm:嵌套对象不是实体中的关系
我想知道嵌套对象内部是否可能存在(由Orm管理的)关系。
在以下情况下:
abstract class BaseEntity {
@PrimaryKey()
_id!: ObjectID;
@SerializedPrimaryKey()
id!: string;
}
@Entity({ tableName: 'users' })
class User extends BaseEntity {
@property()
name!: string;
@OnetoMany(() => Post,'author')
posts = new Collection<Post>(this);
}
@Entity({ tableName: 'posts' })
class Post extends BaseEntity {
// bidirectional relation with users collection:
@ManyToOne(() => User)
author!: IdentifiedReference<User>;
@property()
comments?: Comment[];
}
class Comment {
// unidirectional relation with users collection:
@ManyToOne(() => User)
author!: IdentifiedReference<User>;
@property()
content!: string;
}
但是对于mikro-orm Comment
来说,作者只是ObjectID
而不是对用户实体的引用:
Post {
_id: ObjectId('5f41575784cc27344cafecbe'),user: Ref<User> { _id: ObjectId('5f41575784cc27344cafecbd') },// ref to user entity
title: 'Sample post',comments: [
{
author: ObjectId('5f41575784cc27344cafecbd'),// just a id :<
content: 'Sample comment'
}
]
}
我做错什么了吗?或者根本就不可能吗?
我同时尝试了mikro-orm v3.6.15和@ mikro-orm / core,@ mikro-orm / mongodb v4.0.0-rc.2。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。