我有一个问题,测试HTML输入是否真实,然后通过ORM获取真或假的案例:
open_to_public: (req.param('open_to_public') == 't' ? true: false),
Waterline文档说字符串将无法验证,因此我直接设置布尔值,如上所述。但是,模型无法对此进行验证,结果如下:
{ [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' }
我尝试了大量案例,文字或引用值的组合,并多次调整了我的模型。后端是MySQL,列是boolean类型。列中的现有数据均表示为TRUE / FALSE。
这里是当前匹配的模型定义(导致上面列出的错误):
open_to_public: {
type: 'boolean',
defaultsTo: 'false',
boolean: true,
},
任何见解都表示感谢。
编辑:按照Scott的要求:在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;
});
}
答案 0 :(得分:0)
您可以共享连接设置吗?仅适配器......
尝试类似:open_to_public :( req.param(' open_to_public')==' t'?' true':' false&#39 ),
答案 1 :(得分:0)
您可以尝试更改模型定义
open_to_public: {
type: 'boolean',
defaultsTo: false
},