loopback4 - 如何在环回4中创建三个模型之间的关系?
问题描述
共有三种型号——
- 人物模型 -
import {Entity, model, property} from '@loopback/repository';
@model()
export class Person extends Entity {
@property({
type: 'number',
id: true,
generated: true,
})
id?: number;
@property({
type: 'string',
})
name?: string;
@property({
type: 'number',
required: true,
})
age: number;
constructor(data?: Partial<Person>) {
super(data);
}
}
export interface PersonRelations {
// describe navigational properties here
}
export type PersonWithRelations = Person & PersonRelations;
聊天组模型 -
import {Entity, model, property} from '@loopback/repository';
@model()
export class ChatGroup extends Entity {
@property({
type: 'number',
id: true,
generated: true,
})
id?: number;
@property({
type: 'string',
})
chatGroupName?: string;
constructor(data?: Partial<ChatGroup>) {
super(data);
}
}
export interface ChatGroupRelations {
// describe navigational properties here
}
export type ChatGroupWithRelations = ChatGroup & ChatGroupRelations;
聊天组成员模型 -
import {Entity, model, property} from '@loopback/repository';
@model()
export class ChatGroupMembers extends Entity {
@property({
type: 'number',
id: true,
generated: true,
})
id?: number;
@property({
type: 'number',
required: true,
})
personId: number;
@property({
type: 'number',
required: true,
})
chatGroupId: number;
constructor(data?: Partial<ChatGroupMembers>) {
super(data);
}
}
export interface ChatGroupMembersRelations {
// describe navigational properties here
}
export type ChatGroupMembersWithRelations = ChatGroupMembers & ChatGroupMembersRelations;
人员模型保存有关人名和年龄的信息。聊天组模型保存有关聊天组名称的信息。聊天组成员模型保存有关聊天组成员的信息,这些成员具有来自 Person 模型的 personId 和来自 ChatGroup 模型的 chatGroupId。
有什么方法可以在这些模型之间创建关系,以便我在一次 API 调用中获取聊天组及其成员和姓名的信息?
解决方案
推荐阅读
- python - Django 表单不显示多个表单,多个表单呈现到单个视图中的模板
- windows - Amazon.KinesisFirehose.AmazonKinesisFirehoseException:签名已过期
- sql - 如何同时/并行执行多个 Oracle 存储过程以获得更好的性能?
- javascript - 如何将容器 div 包裹在 Ckeditor 表上 onOk
- android-studio - Android Studio 3.4 卡在索引项目上
- java - Spring 中对 List 或 Map 的响应正文
- javascript - 在 webpack 构建中包含捆绑的 webpack 文件
- angular - 如何更改 Angular Material Datepicker 主题?
- node.js - 保存和检索 req.session 的内容
- python - sqlalchemy ArgumentError:文本 SQL