Skip to content

Instantly share code, notes, and snippets.

@rjmoggach
Created January 31, 2014 23:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rjmoggach/8745781 to your computer and use it in GitHub Desktop.
Save rjmoggach/8745781 to your computer and use it in GitHub Desktop.
waterline issue with null foreign keys
index: function(req, res) {
Person
.find()
.populate('user')
.exec(function peopleFound(err, people) {
console.log(err);
if (err) return res.json(err, 400);
if (!people) return res.json({ error: 'No people exist.' }, 404);
res.json(people);
});
},
destroy: function(req, res) {
var username = req.param('username');
User.findOne({ username: req.param('username') }, function foundUser(err, user) {
if (err) return res.json(err, 400);
Person.update({user: user.id}, {user: null}, function profileUpdated(err, profile) {
if (err) return res.json(err, 400);
});
User.destroy(user.id, function userDestroyed(err) {
if (err) return res.json(err, 400);
return res.json({msg: 'User '+username+' deleted.'}, 200);
});
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment