I have a list of categories and a list of places, each place has an categorieId in foreign key.
categorie.json: http://pastebin.com/ttumKPf9
place.json: http://pastebin.com/J4bdEiUx
I try to verify if the category id exists. For this, i redefine a create method in place class. In place class I search if the category id is present in category. If i find it, i call upsert method for insert the data in place. But this upsert method recall create method... If i don't call upsert method, the data isn't insert. How can I verify and insert the data in strongloop?
script.js:
module.exports = function(app){
var Place = app.models.place;
var Categorie = app.models.categorie;
Place.create = function(data,callback){
console.log("avant find");
console.log(data.id);
Categorie.findById(data.categorieId, function(err, instance){
console.log("find")
if(err){
throw err;
}
if(instance == null){
new err;
throw err;
}
console.log("Upsert");
Place.upsert(data, callback);
});
};
};