Created
January 31, 2014 23:59
-
-
Save rjmoggach/8745781 to your computer and use it in GitHub Desktop.
waterline issue with null foreign keys
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
}); | |
}, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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