mirror of
https://gitee.com/mybatis-flex/mybatis-flex.git
synced 2025-12-08 01:28:24 +08:00
fix: join self error; close #I7M3ZW
This commit is contained in:
parent
655c11a5c6
commit
5161079a78
@ -57,6 +57,14 @@ public class Join implements CloneSupport<Join> {
|
||||
|
||||
|
||||
public void on(QueryCondition condition) {
|
||||
if (condition.column != null){
|
||||
QueryTable table = condition.column.getTable();
|
||||
if (queryTable.isSameTable(table)){
|
||||
QueryColumn newColumn = condition.column.clone();
|
||||
newColumn.table.alias = queryTable.alias;
|
||||
condition.column = newColumn;
|
||||
}
|
||||
}
|
||||
this.on = condition;
|
||||
}
|
||||
|
||||
|
||||
@ -555,30 +555,35 @@ public class QueryColumn implements CloneSupport<QueryColumn> {
|
||||
}
|
||||
|
||||
|
||||
QueryTable getSelectTable(List<QueryTable> queryTables, QueryTable columnTable) {
|
||||
QueryTable getSelectTable(List<QueryTable> queryTables, QueryTable selfTable) {
|
||||
//未查询任何表
|
||||
if (queryTables == null || queryTables.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (queryTables.size() == 1 && queryTables.get(0).isSameTable(columnTable)) {
|
||||
if (selfTable != null && StringUtil.isNotBlank(selfTable.alias)){
|
||||
return selfTable;
|
||||
}
|
||||
|
||||
if (queryTables.size() == 1 && queryTables.get(0).isSameTable(selfTable)) {
|
||||
//ignore table
|
||||
return null;
|
||||
}
|
||||
|
||||
if (CollectionUtil.isEmpty(queryTables)) {
|
||||
return columnTable;
|
||||
return selfTable;
|
||||
}
|
||||
|
||||
if (columnTable == null && queryTables.size() == 1) {
|
||||
if (selfTable == null && queryTables.size() == 1) {
|
||||
return queryTables.get(0);
|
||||
}
|
||||
|
||||
for (QueryTable table : queryTables) {
|
||||
if (table.isSameTable(columnTable)) {
|
||||
if (table.isSameTable(selfTable)) {
|
||||
return table;
|
||||
}
|
||||
}
|
||||
return columnTable;
|
||||
return selfTable;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -172,6 +172,7 @@ public class QueryCondition implements CloneSupport<QueryCondition> {
|
||||
}
|
||||
//列
|
||||
sql.append(getColumn().toConditionSql(queryTables, dialect));
|
||||
|
||||
//逻辑符号
|
||||
sql.append(logic);
|
||||
|
||||
|
||||
@ -348,6 +348,24 @@ public class AccountSqlTester {
|
||||
System.out.println(sql);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testJoinSelf() {
|
||||
QueryWrapper queryWrapper = QueryWrapper.create()
|
||||
.select()
|
||||
.from(ACCOUNT)
|
||||
.leftJoin(ACCOUNT).as("a1").on(ACCOUNT.ID.eq(ACCOUNT.AGE))
|
||||
.where(ACCOUNT.AGE.ge(10));
|
||||
|
||||
System.out.println(queryWrapper.toSQL());
|
||||
|
||||
QueryWrapper queryWrapper1 = QueryWrapper.create()
|
||||
.select(ACCOUNT.ID)
|
||||
.from(ACCOUNT)
|
||||
.where(ACCOUNT.AGE.ge(10));
|
||||
|
||||
System.out.println(queryWrapper1.toSQL());
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testOrderBySql() {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user