2014-07-02 48 views
0

我有感實性問題的情況下測試HTML的輸入,然後得到真或假的情況下通過ORM保存:通過水線(Sailsjs)傳遞布爾值?

open_to_public: (req.param('open_to_public') == 't' ? true: false), 

水線文檔說字符串將無法驗證,所以我設定布爾值直接,如上所述。然而,該模型無法驗證這一點,像這樣的結果:

{ [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,列是布爾類型的。列中的現有數據都表示爲TRUE/FALSE。

這裏的匹配模型定義,因爲它是目前(在上面列出的錯誤結果):

open_to_public: { 
    type: 'boolean', 
    defaultsTo: 'false', 
    boolean: true, 
}, 

任何見解感激理解。

編輯:由斯科特要求:在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

你能證明是代碼給你的錯誤? – sgress454

+0

你確定它是導致這個問題的'open_to_public'字段嗎?你有任何其他布爾字段? – sgress454

回答

0

可以共享連接設置?只有適配器...

試着這麼做:open_to_public:(req.param( 'open_to_public')== 'T' '真': '假'),