2017-02-20 30 views
1

我有一個通過關聯兩個對象,AssignmentTags。他們通過模型AssignmentTag加入。我能夠讀取&這些對象之間的優良寫法,但是當我嘗試更新時,它不會刪除先前的關聯see notes for .update()水線更新通過關聯

我相信我應該能夠將標籤ID數組傳遞給Assignment模型,並刪除當前關聯並更新新關聯。

Assignment.update({id: req.param("assignmentId")}, {tags: tags}) 
       .exec(function (err, updated) { 
        if (err) { 
         return res.serverError(err); 
        } 

        return res.json({ 
         updated 
        } 
       }); 

Assignment.js模式是:

module.exports = { 
     connection: db_connection, 
     tableName: 'assignments', 
     attributes: { 
      id: { 
       type: 'integer', 
       primaryKey: true, 
       autoIncrement: true, 
       unique: true 
      }, 
      title: { 
       type: 'string' 
      }, // varchar(255) 
      description: { 
       type: 'text' 
      }, // text 
      // an assignment may have many tags 
      tags: { 
       collection: 'tag', 
       via: 'assignment', 
       through: 'assignmenttag' 
      }, 
     } 
    }; 

Tag.js模式是:

module.exports = { 
     connection: db_connection, 
     tableName: 'tags', 
     attributes: { 
      id: { 
       type: 'integer', 
       primaryKey: true, 
       autoIncrement: true, 
       unique: true 
      }, 
      title: { 
       type: 'string' 
      }, // varchar(255) 
      description: { 
       type: 'text' 
      }, // text 
      // A tag may have many assignments 
      assignments: { 
       collection: 'assignment', 
       via: 'tag', 
       through: 'assignmenttag' 
      }, 
     } 
    }; 

AssignmentTag.js模式是:

module.exports = { 
     connection: db_conection, 
     tableName: 'assignment_tag', 
     attributes: { 
      id: { 
       type: 'integer', 
       primaryKey: true, 
       autoIncrement: true, 
       unique: true 
      }, 
      assignment: { 
       columnName: 'assignment_id', 
       model: 'assignment' 
      }, 
      tag: { 
       columnName: 'tag_id', 
       model: 'tag' 
      }, 
     } 
    }; 

任何想法,爲什麼標籤作爲社會不會在.update()上下降?


更新:我已經創建水線項目的問題得到一些進一步的幫助。我已經在水線問題上關聯了一個存儲庫中的問題。 https://github.com/balderdashy/waterline/issues/1453


解決:水線大約一個星期後,響應和更新模型關聯,以適應這種要求。見問題:https://github.com/balderdashy/waterline/issues/1453。他們顯然是在即將發佈的版本中重寫這些關聯,所以這個問題應該過時。

回答

0

這是通過發佈在Waterline回購上的以下問題解決的:https://github.com/balderdashy/waterline/issues/1453

+0

你好,請在你的回答中加入一些細節,以便清楚明白並易於理解。 – Chaithanya

+0

看看Waterline附帶的問題。這一切都在該對話中解釋。 – Chase

+0

感謝您的信息。儘管提供到外部資源的鏈接很有幫助,但最好是在答案中提供解決方案,並使用超鏈接作爲參考。請參閱http://stackoverflow.com/help/how-to-answer,瞭解如何編寫出色答案的提示。 – Chaithanya