我为客户端使用了这个typedef:
Parent Line View
和这个会话:
type Client {
c_id: ID!
fname: String!
lname: String!
gender: Gender!
birthdate: Date!
date_added: Date!
last_opened: Date!
p_id: Int!
no_of_sessions: Int
sessions: [Session]!
}
我的意思是进行嵌套包含,其中返回的会话基于客户端ID并返回如下内容:
type Session {
session_id: ID!
session_name: String!
date_of_session: Date!
c_id: Int!
}
我为每种模型的关联创建了别名:
"getClient": {
"fname": "Jake",
"lname": "Finn",
"sessions": [{
"session_name":"session 1"
},
{
"session_name":"session 2"
},
]
}
这是我的解析器:
//Client Association
Client.hasMany(models.Session, {
as: 'sessions',
foreignKey: 'c_id'
});
//Session Association
Session.belongsTo(models.Client, {
as: 'client',
foreignKey: 'c_id',
onDelete: 'CASCADE',
onUpdate: 'CASCADE'
});
但是结果显示为:
getClient: ({ c_id }) =>
models.Client.findOne({
raw: true,
include: [
{
model: models.Session,
as: 'sessions',
attributes: [],
required: false,
where: { c_id },
}
],
where: { c_id }
})
我希望能够弄清楚为什么嵌套的include结果返回null。我正在使用sql作为数据库。