Микро-орм: отношения во вложенных объектах (не в сущностях)
Мне интересно, можно ли иметь (управляемые 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;
}
в базе данных отдельный пост выглядит так:
но для микро-орма 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.