2014-01-08 36 views
2

因此,使用sailsJS,您可以將任何舊數據放入模型中,並將其放入數據庫中,即使該項目未在attributes對象中定義。SailsJS阻止不需要的數據進入數據庫

有什麼辦法可以防止這種情況發生?看起來很愚蠢,試着做一個if,然後拋出錯誤,因爲會有太多事情不能通過。

比如剛纔我碰到了在那裏我有一個用戶列表,我被角ng-repeat在前端顯示它們,當我put數據保存用戶也決定"$$hashKey": "00I"與去問題他們也是

所以它會自動保存到數據庫中,當我刷新和重新獲取數據時,"$$hashKey": "00I"是回來,所以造成這個錯誤

Error: [ngRepeat:dupes] Duplicates in a repeater are not allowed. Use 'track by' expression to specify unique keys. Repeater: (key, user) in admins | filter:userSearch, Duplicate key: object:00I

這是從角來。

PS。

as far as i know, the server is using the default sails-disk

回答

4

Sails.js模型的默認模式是無模式的,這可能不是您所需要的。所以,你需要做的就是要架構添加到模型:

module.exports = { 
schema: true, 

attributes: { 
    // Define all your attributes here... 
} 
}; 

之後未在attributes描述的所有值將模型保存過程中被自動過濾掉。

+0

很好,謝謝。 – iConnor