我有异议模型:
applicant.js
static get jsonSchema() {
return {...}
static relationMappings() {
// Import models here to prevent require loops.
const Interview = require("./interview");
const User = require("./user");
return {
users: {
relation: Model.ManyToManyRelation,
modelClass: User,
join: {
from: "applicants.nik",
through: {
from: "interviews.applicantId",
to: "interviews.userId"
},
to: "users.id"
}
}
};
}
user.js
static relationMappings() {
// Import models here to prevent require loops.
const Applicant = require("./applicant");
const Role = require("./role");
return {
applicants: {
relation: Model.ManyToManyRelation,
modelClass: Applicant,
join: {
from: "users.id",
through: {
from: "interviews.userId",
to: "interviews.applicantId"
},
to: "applicants.nik"
}
}
};
}
M-N表,采访。
static relationMappings() {
const Applicant = require("./applicant");
const User = require("./user");
return {
applicants: {
relation: Model.BelongsToOneRelation,
modelClass: Applicant,
join: {
from: "interviews.applicantId",
to: "applicants.nik"
}
},
users: {
relation: Model.BelongsToOneRelation,
modelClass: User,
join: {
from: "interviews.userId",
to: "users.id"
}
}
};
我想做什么: -使用GraphQl 显示申请人表和用户表中的数据
{
applicants{
nik
full_name
email
interviews{
applicantId
state
}
} }
这导致了急切加载的使用。 所需的结果是一个带有申请人数据的对象实例,并且在对象内部嵌套了访谈数据。