protected static function mapToDatabase($type, $valueName) {
    $mapper = self::getMapper($type);
    if ($mapper->hasAttribute($valueName)) {
      $attributeDescription = $mapper->getAttribute($valueName);
    }
    else {
      // if the attribute does not exist, it might be the column name already
      foreach ($mapper->getAttributes() as $curAttributeDesc) {
        if ($curAttributeDesc->getColumn() == $valueName) {
          $attributeDescription = $curAttributeDesc;
          break;
        }
      }
    }
    if (!$attributeDescription) {
      throw new PersistenceException("No attribute '".$valueName."' exists in '".$type."'");
    }

    $table = $mapper->getRealTableName();
    $column = $attributeDescription->getColumn();
    return [$table, $column];
  }