@@ -453,8 +453,14 @@ protected function parseWhereExp(string $logic, $field, $op, $condition, array $
453
453
{
454
454
$ logic = strtoupper ($ logic );
455
455
456
+ // 字段映射
457
+ $ map = $ this ->getOption ('field_map ' , []);
458
+ if (is_string ($ field ) && isset ($ map [$ field ])) {
459
+ $ field = $ map [$ field ];
460
+ }
461
+
456
462
// 处理 via
457
- if (is_string ($ field ) && !empty ($ this ->options ['via ' ]) && !str_contains ($ field , '. ' )) {
463
+ if (is_string ($ field ) && !empty ($ this ->options ['via ' ]) && !str_contains ($ field , '. ' ) && ! str_contains ( $ field , ' -> ' ) ) {
458
464
$ field = $ this ->options ['via ' ] . '. ' . $ field ;
459
465
}
460
466
@@ -522,19 +528,15 @@ protected function parseWhereItem(string $logic, $field, $op, $condition, array
522
528
array_unshift ($ param , $ field );
523
529
return $ param ;
524
530
}
525
- // 获取字段映射
526
- $ alias = $ this ->getFieldMap ($ field );
527
- if ($ alias ) {
528
- $ field = $ alias ;
529
- if (strpos ($ alias , '-> ' )) {
530
- [$ relation , $ field ] = explode ('-> ' , $ alias , 2 );
531
-
532
- $ type = $ this ->getFieldType ($ relation );
533
- if (is_null ($ type )) {
534
- // 自动关联查询
535
- $ this ->hasWhere ($ relation , [[$ field , is_null ($ condition ) ? '= ' : $ op , $ condition ?? $ op ]]);
536
- return [];
537
- }
531
+
532
+ if (is_string ($ field ) && strpos ($ field , '-> ' )) {
533
+ [$ relation , $ attr ] = explode ('-> ' , $ field , 2 );
534
+
535
+ $ type = $ this ->getFieldType ($ relation );
536
+ if (is_null ($ type )) {
537
+ // 自动关联查询
538
+ $ this ->hasWhere ($ relation , [[$ attr , is_null ($ condition ) ? '= ' : $ op , $ condition ?? $ op ]]);
539
+ return [];
538
540
}
539
541
}
540
542
0 commit comments