When I try to create a new instance of a transaction (one of my models) Sails throws an error. I'm using Sails v0.10.2, Waterline v0.10.6 and sails-mysql v0.10.5 (all of which, I believe, are the latest versions).
My code looks like this:
var transObj = {
amount: req.param('fund'),
loan: req.param('loanId'),
lender: req.param('userId')
};
// This throws an error
Transaction.create(transObj, function (err, trans){
console.log('Transaction created');
});
Strangely, I do not get an error when I do User.create() elsewhere in my app.
I have a workaround in place, using Transaction.query(), but this does not give me the row's id in the callback which is an issue.
I've seen similar-ish discussions elsewhere, but most people seem to get this resolved by updating Sails and/or Waterline.
Can anyone offer suggestions?
Can you post your model? Seems like you might have a typo in the Transaction model. Make sure you use required instead of require for any validations.
Oops, my bad. Yup, that was the issue @particlebanana. Many thanks for the quick response.
Most helpful comment
Can you post your model? Seems like you might have a typo in the Transaction model. Make sure you use
requiredinstead ofrequirefor any validations.