mirror of
https://gitee.com/mybatis-flex/mybatis-flex.git
synced 2025-12-08 09:38:26 +08:00
update mybatis-flex-core/src/main/java/com/mybatisflex/core/query/MapperQueryChain.java.
使用relation关联查询的时候,更多情况下是【目的明确】的只查询某几个关联,所以只需要调用addQueryRelations即可。addIgnoreRelations的这种反向操作不利点是,后续的关系有拓展了,原来使用ignore方式的,会进行不必要的关联查询。 Signed-off-by: 唐振超 <imtzc@qq.com>
This commit is contained in:
parent
0817ce4c4b
commit
d1f7b67724
@ -18,8 +18,12 @@ package com.mybatisflex.core.query;
|
|||||||
|
|
||||||
import com.mybatisflex.core.BaseMapper;
|
import com.mybatisflex.core.BaseMapper;
|
||||||
import com.mybatisflex.core.paginate.Page;
|
import com.mybatisflex.core.paginate.Page;
|
||||||
|
import com.mybatisflex.core.relation.RelationManager;
|
||||||
|
import com.mybatisflex.core.util.LambdaGetter;
|
||||||
|
import com.mybatisflex.core.util.LambdaUtil;
|
||||||
import com.mybatisflex.core.util.SqlUtil;
|
import com.mybatisflex.core.util.SqlUtil;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
@ -194,4 +198,19 @@ public interface MapperQueryChain<T> extends ChainQuery<T> {
|
|||||||
return new RelationsBuilder<>(this);
|
return new RelationsBuilder<>(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 使用 Relations Query 的方式进行关联查询。
|
||||||
|
* @param columns 需要关联的字段
|
||||||
|
* @return Relations Query 查询
|
||||||
|
*/
|
||||||
|
default RelationsBuilder<T> withRelations(LambdaGetter<T>... columns) {
|
||||||
|
if(columns != null && columns.length > 0) {
|
||||||
|
String[] array = Arrays.stream(columns)
|
||||||
|
.map(LambdaUtil::getFieldName)
|
||||||
|
.toArray(String[]::new);
|
||||||
|
RelationManager.addQueryRelations(array);
|
||||||
|
}
|
||||||
|
return new RelationsBuilder<>(this);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user