2016-01-28 31 views
0

我正在進行權限管理。我在db中爲admin創建了另一個表並創建了一個數據inf。但是,當我搜索它沒有工作。錯誤:必須包含引用適配器使用的`adapter`鍵

以下是在API /控制器/ AdminController.js代碼

checkUN: function(req, res) { 
    var name = req.param('name'); 

    Admin.find({ 
     name: name 
    }).exec(function findOneCB(err, admins) { 
     // print in terminal correctly 
     console.log('name:'+name); 

     if (err) { 
      // console.log('err'); 
      // did not enter this judgment 
      // res.redirect('admin/login'); 
      return res.json({ 
       error: 'This user name does not exist' 
      }); 
     } 
     // return res.view("user/addUser", { 
     //  admins: admins 
     // }); 
    }); 
}, 

有在終端或瀏覽器console.Then沒有錯誤INF我增加了connectiontableName每個車型。

這裏是API /型號編碼/ Admin.js

module.exports = { 
    connection: 'applicationform', 
    tableName: 'Admin', 
    attributes: { 
    name: { 
     type: 'string' 
    }, 
    password: { 
     type: 'string' 
    }, 
    email: { 
     type: 'string' 
    }, 
    createdAt: { 
     type: 'datetime', 
     defaultsTo: function(){ return new Date(); } 
    }, 
    updatedAt: { 
     type: 'datetime', 
     defaultsTo: function(){ return new Date(); } 
    } 
    } 
    }; 

這裏是終端錯誤INF:

error: In model (admin), invalid connection :: applicationform
error: Must contain an adapter key referencing the adapter to use.

這是我的配置/ connections.js代碼。

mysql: { 
    adapter : 'sails-mysql', 
    host  : 'localhost', 
    port  : 3306, 
    user  : 'root', 
    password : '1', 
    database : 'applicationform' 
}, 

回答

0

您連接的名稱是mysql,不applicationform,這是數據庫名。

在模型定義中將applicationform替換爲mysql作爲connection,它應該可以工作。

+0

我不認爲你會得到一個錯誤,但是如果你的查詢沒有找到結果,結果爲空數組 – elssar

+0

謝謝elssar!我弄錯了。 –

相關問題