mirror of
https://github.com/ebean-orm/ebean.git
synced 2026-11-18 14:58:47 +00:00
Fixes to only allow m2m intersection save from one direction based on
beanName. Supports BUG 429 : Pull Request: jroper - Fixing ManyToMany association saving bug
This commit is contained in:
1 parent
21d63c7424
commit
bca787b54d
4 files changed
+41
-3
No files matched your search
@@ -117,6 +117,7 @@ public class JdbcTransaction implements SpiTransaction {
|
||||
|
||||
HashSet<Object> persistingBeans = new HashSet<Object>();
|
||||
HashSet<Integer> deletingBeansHash;
|
||||
HashMap<String,String> m2mIntersectionSave;
|
||||
|
||||
TransactionLogBuffer logBuffer;
|
||||
|
||||
@@ -223,6 +224,30 @@ public class JdbcTransaction implements SpiTransaction {
|
||||
return !persistingBeans.add(bean);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return true if the m2m intersection save is allowed from a given bean direction.
|
||||
* This is to stop m2m intersection management via both directions of a m2m.
|
||||
*/
|
||||
@Override
|
||||
public boolean isSaveAssocManyIntersection(String intersectionTable, String beanName) {
|
||||
if (m2mIntersectionSave == null) {
|
||||
// first attempt so yes allow this m2m intersection direction
|
||||
m2mIntersectionSave = new HashMap<String, String>();
|
||||
m2mIntersectionSave.put(intersectionTable, beanName);
|
||||
return true;
|
||||
}
|
||||
String existingBean = m2mIntersectionSave.get(intersectionTable);
|
||||
if (existingBean == null) {
|
||||
// first time into this intersection table so allow
|
||||
m2mIntersectionSave.put(intersectionTable, beanName);
|
||||
return true;
|
||||
}
|
||||
|
||||
// only allow if save coming from the same bean type
|
||||
// to stop saves coming from both directions of m2m
|
||||
return existingBean.equals(beanName);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the depth of the current persist request plus the diff. This has the
|
||||
* effect of changing the current depth and returning the new value. Pass
|
||||
|
||||
Reference in new issue
Block a user