mirror of
https://github.com/ebean-orm/ebean.git
synced 2024-04-21 10:51:47 +00:00
#2238 - Select with disjunction of expressions over OneToOne relationship missing join clause
Noting that there might be a better fix. The addJoin() at line 151 is suppressed as it is a duplicate for this case of a !oneToOneExported so a better fix might be to only add the soft delete clause when the join as actually added (not suppressed as a duplicate).
This commit is contained in:
@@ -143,13 +143,13 @@ class SqlTreeNodeExtraJoin implements SqlTreeNode {
|
||||
// "promote" to left join as the path contains a many
|
||||
joinType = SqlJoinType.OUTER;
|
||||
}
|
||||
if (!manyToMany && !oneToOneExported) {
|
||||
if (!manyToMany) {
|
||||
if (assocBeanProperty.isFormula()) {
|
||||
// add joins for formula beans
|
||||
assocBeanProperty.appendFrom(ctx, joinType);
|
||||
}
|
||||
joinType = assocBeanProperty.addJoin(joinType, prefix, ctx);
|
||||
if (assocBeanProperty.isTargetSoftDelete() && temporalMode != SpiQuery.TemporalMode.SOFT_DELETED) {
|
||||
if (!oneToOneExported && assocBeanProperty.isTargetSoftDelete() && temporalMode != SpiQuery.TemporalMode.SOFT_DELETED) {
|
||||
ctx.append(" and ").append(assocBeanProperty.getSoftDeletePredicate(ctx.getTableAlias(prefix)));
|
||||
}
|
||||
}
|
||||
|
||||
+8
-1
@@ -3,12 +3,14 @@ package org.tests.softdelete;
|
||||
import io.ebean.BaseTestCase;
|
||||
import io.ebean.DB;
|
||||
import io.ebean.Ebean;
|
||||
import org.ebeantest.LoggedSqlCollector;
|
||||
import org.tests.model.softdelete.ESoftDelMid;
|
||||
import io.ebean.Finder;
|
||||
import org.junit.Test;
|
||||
import org.tests.model.softdelete.ESoftDelY;
|
||||
import org.tests.model.softdelete.ESoftDelZ;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
@@ -44,6 +46,8 @@ public class TestSoftDeleteOptionalRelationship extends BaseTestCase {
|
||||
DB.save(y);
|
||||
}
|
||||
|
||||
LoggedSqlCollector.start();
|
||||
|
||||
Finder<Long, ESoftDelY> finder = new Finder<>(ESoftDelY.class);
|
||||
ESoftDelY bean = finder
|
||||
.query()
|
||||
@@ -53,7 +57,10 @@ public class TestSoftDeleteOptionalRelationship extends BaseTestCase {
|
||||
.findOne();
|
||||
|
||||
assertThat(bean).isNotNull();
|
||||
|
||||
final List<String> sql = LoggedSqlCollector.stop();
|
||||
assertThat(sql).hasSize(1);
|
||||
assertThat(sql.get(0)).contains("left join esoft_del_z t1 on t1.id = t0.organization_id and t1.deleted = false where");
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user