#1765 - Wrong SQL generated on m2m and OrderBy (Regression of #1746)

This commit is contained in:
rob bygrave
2019-07-19 10:43:07 +12:00
parent 8b670fd615
commit bcb136b692
3 changed files with 42 additions and 7 deletions
@@ -0,0 +1,36 @@
package org.tests.m2m;
import io.ebean.BaseTestCase;
import io.ebean.DB;
import io.ebean.annotation.ForPlatform;
import io.ebean.annotation.Platform;
import io.ebeantest.LoggedSql;
import org.junit.Test;
import org.tests.model.m2m.Permission;
import org.tests.model.m2m.Role;
import java.util.List;
import static org.assertj.core.api.Assertions.assertThat;
public class TestM2MDistinct_sqlServer extends BaseTestCase {
@ForPlatform(Platform.SQLSERVER)
@Test
public void testName() {
Permission perm = new Permission("TestPerm");
DB.save(perm);
LoggedSql.start();
List<Role> roles = DB.find(Role.class).where().eq("permissions", perm)
.order().asc("name", "Latin1_General_CI_AS")
.findList();
List<String> sqls = LoggedSql.stop();
assertThat(sqls.get(0)).startsWith("select distinct t0.id, t0.name, t0.version, t0.tenant_id, t0.name collate Latin1_General_CI_AS "
+ "from mt_role t0 join mt_role_permission u1z_ on u1z_.mt_role_id = t0.id "
+ "join mt_permission u1 on u1.id = u1z_.mt_permission_id where u1.id = ? "
+ "order by t0.name collate Latin1_General_CI_AS;");
}
}