public static function getRelationQueryCondition($node, $otherRole) {
    $mapper = $node->getMapper();
    $relationDescription = $mapper->getRelation($otherRole);
    $otherType = $relationDescription->getOtherType();

    $query = new ObjectQuery($otherType, __CLASS__.__METHOD__.$node->getType().$otherRole);
    // add the primary keys of the node
    // using the role name as alias (avoids ambiguous paths)
    $nodeTpl = $query->getObjectTemplate($node->getType(), $relationDescription->getThisRole());
    $oid = $node->getOID();
    $ids = $oid->getId();
    $i = 0;
    foreach ($mapper->getPkNames() as $pkName) {
      $nodeTpl->setValue($pkName, Criteria::asValue("=", $ids[$i++]));
    }
    // add the other type in the given relation
    $otherTpl = $query->getObjectTemplate($otherType);
    $nodeTpl->addNode($otherTpl, $otherRole);
    $condition = $query->getQueryCondition();
    // prevent selecting all objects, if the condition is empty
    if (strlen($condition) == 0) {
      $condition = 0;
    }
    return $condition;
  }