I have a problem case testing HTML input for truthiness, and then getting the true or false case to save through the ORM:
open_to_public: (req.param('open_to_public') == 't' ? true: false),
The Waterline docs say that strings will fail to validate, so I set boolean values directly, as above. However, the model fails to validate this, with results like this:
{ [error: invalid input syntax for type boolean: ""]
name: 'error',
length: 83,
severity: 'ERROR',
code: '22P02',
detail: undefined,
hint: undefined,
position: undefined,
internalPosition: undefined,
internalQuery: undefined,
where: undefined,
file: 'bool.c',
line: '153',
routine: 'boolin' }
I have tried any number of combinations of case, literals or quoted values, and have adjusted my model multiple times. The backend is MySQL, and the column is typed boolean. Existing data in the column all represent as TRUE/FALSE.
Here's the matching model definition as it is currently (results in the error listed above):
open_to_public: {
type: 'boolean',
defaultsTo: 'false',
boolean: true,
},
Any insights gratefully appreciated.
EDIT: as requested by Scott: in LeaseController.js
create: function(req,res,next) {
if( req.param('client_id') == null || req.param('rental_type_id') == null ) {
console.log( 'Minimum requirements missing' );
return next();
}
var data = {
client_id: req.param('client_id'),
rental_type_id: req.param('rental_type_id'),
clerk: req.session.user.login,
site_contact_person: req.param('site_contact_person'),
site_contact_phone: req.param('site_contact_phone'),
open_to_public: (req.param('open_to_public') == 't' ? true: false),
admission_fee: (req.param('admission_fee') ? req.param('admission_fee'): 0.00),
rental_confirmation: req.param('rental_confirmation'),
require_deposit: (req.param('require_deposit')?req.param('require_deposit'):0.00)
};
Lease.create( data ).done(function(err,lease){
if( err ) {
///// THIS IS WHERE THE ERR IS THROWN //////
console.log( err );
console.log( data );
return next();
}
if( ! lease ) {
console.log( 'No lease object returned from create function' );
return next();
}
req.flash('success', 'Lease '+ lease.id + ' created');
res.redirect( '/lease/'+lease.id, {data:lease} );
return;
});
}