if ($cascade instanceof ManyToManyAssociationField
) { continue;
} // many to one shouldn't be cascaded
if ($cascade instanceof ManyToOneAssociationField
) { continue;
} $reference =
$cascade->
getReferenceDefinition();
$childrenAware =
$reference->
isChildrenAware();
// first level of parent-child tree?
if ($childrenAware &&
$reference !==
$definition) { // where product.children.parentId IS NULL
$nested->
addFilter(new EqualsFilter($reference->
getEntityName() . '.parentId', null
));
} if ($cascade instanceof ChildrenAssociationField
) { // break endless loop
if ($childCounter >= 30 || !
$cloneChildren) { $criteria->
removeAssociation($cascade->
getPropertyName());