laravel - GraphQL Where Select 子查询
问题描述
这些天,我研究GraphQL
了Laravel
框架,灯塔图书馆。我试过做那种SELECT Query
。
结果,我不知道 GraphQL 可以选择下面的 SQL Query
SELECT * FROM TABLE_A WHERE type=1 AND chart_id=(SELECT id FROM TABLE_B WHERE phone='0000~~')
我希望,客户端首先从这个查询中得到结果。
SELECT id FROM TABLE_B WHERE phone='0000~~'
然后做第二个查询,我想我可以得到一个结果。
但我想知道我能从 1 个请求中得到结果。谢谢。
解决方案
您可以尝试以下
$phoneNumber = '0000~~';
$data = DB::table('tableA')->where('type',1)
->whereIn('chart_id',function($query) use ($phoneNumber) {
$query->select('id')
->from('tableB')
->where('phone', '=',$phoneNumber);
})->get();
如果两者之间有关系tableA
,tableB
您可以执行以下操作
TableA::where('type',1)
->whereHas('tableBRelationshipName', function ($q) use ($phoneNumber) {
$q->select('id')
$q->where('phone','=',$phoneNumber);
})->get();
推荐阅读
- html - 如何分别滚动多个水平滚动容器?
- c++ - CMake 的 Google-Mock/Test 编译器错误
- xaml - 如何修复输入字符串的格式不正确
- scala - Scala - 将函数传递给 Future.apply
- javascript - 未捕获的 ReferenceError:使用 btn 按钮分配的左侧无效
- python - 使用 findContours(cv2) 切片图像
- git - Jenkins 和 GIT - 在 webhook 事件上开始构建作业而不从 GIT 中提取源代码
- ios - 如何在 iOS 应用程序中编辑“弹丸”的速度
- android - 应用程序被杀死时的后台操作?(Android API 23+)
- python - 使用低通滤波器的 Python 视频稳定器