【问题标题】:Questions about using @eq and @paginate in same query for data search关于在同一查询中使用@eq 和@paginate 进行数据搜索的问题
【发布时间】:2020-09-02 07:09:48
【问题描述】:

这是我的数据库表:

这是我的查询:

products(
        product_id: String! @eq
        orderBy: _ @orderBy(columns: ["created_at", "product_id"])
    ): [Product!]! @paginate(defaultCount: 10)

第一个问题是:
我需要这样通过它

products( product_id: "" or null )

它会从 db 中返回任何内容。但是我想在“product_id”得到空字符串或null时返回所有数据。
当“product_id”为空字符串或为空时,有什么方法可以忽略“product_id”?

第二个问题是:
如您所见,数据库表 如果我想使用“product_langs”表中的“产品名称”进行查询以搜索“产品”表。 @eq 在这种情况下似乎不支持。这个案子有什么建议吗?
或者我需要使用自定义搜索和分页创建查询?如果是,我该怎么做?有没有关于如何创建自定义分页和搜索的示例?


谢谢和问候!

【问题讨论】:

    标签: laravel lighthouse laravel-lighthouse


    【解决方案1】:

    我目前无法试用,因此未经测试。 请注意,我是新手,仅提供建议,因为这已经有一段时间没有得到答复了。

    关于您的第一个问题,请尝试删除 ! 看看会发生什么。这应该值得一试。

    
    product_id: String! @eq
    product_id: String @eq
    
    

    你也可以试试这个 https://lighthouse-php.com/master/eloquent/complex-where-conditions.html

    对于您的第二个问题,我相信这就是您要寻找的。​​p>

    https://lighthouse-php.com/master/eloquent/complex-where-conditions.html#wherehasconditions

    假设您正在 eloquent 中在您的 Product 模型上定义关系 productLang。

    
    products(
            hasProductLang: _ @whereHasConditions(columns: ["product_name"])
            orderBy: _ @orderBy(columns: ["created_at", "product_id"])
        ): [Product!]! @paginate(defaultCount: 10)
    
    
    
    products(hasProductLang: { column: PRODUCT_NAME, operator: EQ, value: $searchString })
    
    

    【讨论】:

      猜你喜欢
      • 2021-12-15
      • 1970-01-01
      • 2020-06-06
      • 2016-02-07
      • 1970-01-01
      • 1970-01-01
      • 2018-11-06
      • 2023-03-18
      • 1970-01-01
      相关资源
      最近更新 更多