include_once "../" . $app['framework'] . "Autoloader.class.php";
Autoloader::setCacheFilePath(APP_PATH . 'tmp/class_path_cache.txt');
Autoloader::excludeFolderNamesMatchingRegex('/^CVS|\\..*$/');
Autoloader::setClassPaths(array('../' . $app['framework'], '../entities/', '../lib/'));
spl_autoload_register(array('Autoloader', 'loadClass'));
$v = $_GET;
$relacion = new ArticulosPropiedades();
$rows = $relacion->cargaCondicion("Id", "IDArticulo='{$v['idArticulo']}' and IDPropiedad='{$v['idPropiedad']}'");
$idRelacion = $rows[0]['Id'];
if (!$idRelacion) {
    // Hacer relacion
    $relacion = new ArticulosPropiedades();
    $relacion->setIDArticulo($v['idArticulo']);
    $relacion->setIDPropiedad($v['idPropiedad']);
    $relacion->setIDValor($v['idValor']);
    $relacion->setPublish(1);
    $relacion->create();
} else {
    if ($v['idValor'] > 0) {
        // Actualizar la relación
        $relacion = new ArticulosPropiedades($idRelacion);
        $relacion->setIDValor($v['idValor']);
        $relacion->save();
    } else {
        // Borrar la relación
        $relacion = new ArticulosPropiedades($idRelacion);
        $relacion->erase();
    }
}
$tag = $relacion->getErrores();
$tag = $tag[0];