有没有办法用findByOrFail(或其他方法,如find等)自动加载关系?
在下面的代码中,方法 with()
是没有定义的。
async show({ params, response }) {
try {
return await Company.findByOrFail('domain', params.id).with('websites')
} catch (error) {
console.error(error)
switch (error.name) {
case 'ModelNotFoundException':
return response.notFound({ message: 'companies_show_not_found' })
default:
return response.badRequest({ message: 'something_went_wrong' })
}
}
}
解决方案:
为什么不直接用query like来做呢?
await Company.query().where('domain', params.id).with('websites').firstOrFail()
本文来自投稿,不代表运维实战侠立场,如若转载,请注明出处:https://www.shizhanxia.com/3563.html