laravel-wherehasin
laravel-wherehasin copied to clipboard
Laravel wherehasin是一个可以提升Laravel ORM关联关系查询性能的扩展包,可以替代Laravel ORM中的whereHas以及whereHasMorphIn查询方法。
$q->from("{$databaseName}.{$table}"); 更改为 $q->fromRaw("{$databaseName}.{$prefix}{$table}"); 貌似兼容性更好 from多态关联whereHasMorphIn如果定义了表前缀可能产生错误的sql比如: select * from `lu_auth` where ((`lu_auth`.`lsc` = ? and `lu_auth`.`lid` in (select `lu_mate`.`id` from `lu_lu_db_qiaolu_idc`.`mate` where `lu_auth`.`lid` = `lu_mate`.`id` and `id` = ?)))
select * from `test_users` where `test_users`.`id` in ( select `test_user_profiles`.`user_id` from `test_user_profiles` where `test_users`.`id` = `test_user_profiles`.`user_id` ) 改成以下类型 select * from `test_users` where `test_users`.`id` in ( select `test_user_profiles`.`user_id` from `test_user_profiles`...
使用whereHasIn产生的语句 ``` select count(*) as aggregate from `users` where (`users`.`pid` in (select `users`.`id` from `users` where `users`.`pid` = `users`.`id` and `username` like '%test%')); ``` 使用whereHas产生的语句 ``` select count(*) as aggregate...
 劳烦 @jqhph 看看,感谢
whereHasIn('a.b')  实际的 .id 并非 模型中定义的 house_id 而用 whereHas  依然是按照 模型定义的 字段来查询的. 请大佬回复下.
 我一开始使用的whereHas闭包里面也是whereHas,数据正常。 今天替换了所有的whereHas为whereHasIn,发现在闭包里面用whereHasIn的结果是错误的(空)。 把闭包中的whereHasIn换成whereHas后正常了(如上图)。
 