Al no encontrar la manera en que la validación se haga a nivel de modelo de forma automática al ser una relación, tuve que hacerlo de forma manual en el archivo neighborhood.js
agregando un hook en before save
.
Aquí les dejo una solución al problema. Espero les sirva.
module.exports = function (Neighborhood) {
Neighborhood.observe('before save', function verifyForeignKeys(ctx, next) {
if (ctx.instance) { // for single model update
// check ctx.instance.fkField
var s = ctx.instance;
var countryId = s.__data.countryId;
//Get the Application object which the model attached to, and we do what ever we want
Neighborhood.getApp(function (err, app) {
//App object returned in the callback
//PersistedModel.exists(id, callback ((err, exists)))
app.models.Country.exists(countryId, function (err, exists) {
if (err) throw err;
if (!exists)
return next(new Error('Bad foreign key...'));
});
});
next();
}});
}