0

这是我的数据库表: 这是我的查询:
在此处输入图像描述

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”?

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


谢谢并恭祝安康!

4

1 回答 1

0

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

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


product_id: String! @eq
product_id: String @eq

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

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

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

假设您正在雄辩地定义模型productLang上的关系。Product


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 })

于 2020-05-29T11:59:09.510 回答