mirror of
https://github.com/ebean-orm/ebean.git
synced 2026-10-24 15:55:55 +00:00
Fix for #157 - Regression for @OrderBy on a @ManyToMany property due to change from issue 154
This commit is contained in:
@@ -153,8 +153,9 @@ public class BeanPropertyAssocMany<T> extends BeanPropertyAssoc<T> {
|
||||
if (i > 0) {
|
||||
sb.append(", ");
|
||||
}
|
||||
// these fkcolumns always on base table hence t0 as alias
|
||||
sb.append("t0.").append(exportedProperties[i].getForeignDbColumn());
|
||||
// these fk columns are either on the intersection (int_) or base table (t0)
|
||||
String fkTableAlias = isManyToMany() ? "int_" : "t0";
|
||||
sb.append(fkTableAlias).append(".").append(exportedProperties[i].getForeignDbColumn());
|
||||
}
|
||||
if (fetchOrderBy != null) {
|
||||
sb.append(", ").append(fetchOrderBy);
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package com.avaje.tests.m2m;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import javax.persistence.PersistenceException;
|
||||
|
||||
import org.junit.Assert;
|
||||
@@ -27,6 +29,11 @@ public class TestM2MDeleteNoCascade extends BaseTestCase {
|
||||
|
||||
Ebean.save(u0);
|
||||
|
||||
MnocUser loadedUser = Ebean.find(MnocUser.class, u0.getUserId());
|
||||
List<MnocRole> validRoles = loadedUser.getValidRoles();
|
||||
|
||||
Assert.assertEquals(2, validRoles.size());
|
||||
|
||||
try {
|
||||
Ebean.delete(u0);
|
||||
Assert.assertTrue("expecting an exception", false);
|
||||
|
||||
@@ -7,6 +7,7 @@ import javax.persistence.CascadeType;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.ManyToMany;
|
||||
import javax.persistence.OrderBy;
|
||||
import javax.persistence.Version;
|
||||
|
||||
@Entity
|
||||
@@ -22,6 +23,7 @@ public class MnocUser {
|
||||
|
||||
// No cascade REMOVE
|
||||
@ManyToMany(cascade=CascadeType.PERSIST)
|
||||
@OrderBy("roleName")
|
||||
List<MnocRole> validRoles;
|
||||
|
||||
public MnocUser() {
|
||||
|
||||
Reference in New Issue
Block a user