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;
}

数据库单篇文章中的内容如下:

enter image description here

但是对于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 (将#修改为@)