top-think / think-orm

Think ORM——the PHP Database&ORM Framework
Apache License 2.0
413 stars 171 forks source link

json_contains #627

Closed flowerwOw0316 closed 5 days ago

flowerwOw0316 commented 2 weeks ago

这个函数频率使用还挺高的,请问像laravel的whereJsonContains和orWhereJsonContains这样的方法有吗?

big-dream commented 1 week ago

目前暂时没有,可以先使用 ->whereRaw('JSON_CONTAINS(extra, 1, "$.a")')

liu21st commented 1 week ago

JSON_CONTAINS并好用 还不如直接用 where('json->name','think')呢

flowerwOw0316 commented 1 week ago

没有,我有一个字段存区域信息是这样存的[["11", "110102"], ["11", "110105"], ["11", "110106"], ["11", "110107"]],这样前端只需要传一些匹配的值给我使用JSON_CONTAINS就特别方便

big-dream commented 5 days ago

可以试试最新开发版的 ->whereJsonContains()->whereOrJsonContains() 方法

https://github.com/top-think/think-orm/blob/399200e3540660ffcef5482f066c1786bd935579/src/db/concern/WhereQuery.php#L276-L301