【问题标题】:GraphQL Where Select Sub QueryGraphQL Where Select 子查询
【发布时间】:2020-01-06 01:41:09
【问题描述】:

这些天,我研究了GraphQLLaravel 框架,Lighthouse Library。 我尝试过类似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 个请求中获得结果。谢谢。

【问题讨论】:

  • tableAtableB之间有关系吗??
  • @MikeRoss 是的。 TableA 具有名为chart_id 的外键。 chart_id 是 TableB 的键

标签: laravel graphql laravel-lighthouse


【解决方案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();

如果tableAtableB 之间有关系,您可以执行以下操作

 TableA::where('type',1)
        ->whereHas('tableBRelationshipName', function ($q) use ($phoneNumber) {
             $q->select('id')
             $q->where('phone','=',$phoneNumber);
 })->get();

【讨论】:

    猜你喜欢
    • 2012-04-18
    • 2022-09-27
    • 1970-01-01
    • 1970-01-01
    • 2012-10-28
    • 2011-10-20
    • 1970-01-01
    • 1970-01-01
    • 2020-04-28
    相关资源
    最近更新 更多