2017-02-20 14 views
1

私は2つのオブジェクトのスルーアソシエーションをAssignmentTagsとしました。それらはモデルAssignmentTagによって結合されます。私は&これらのオブジェクト間の書き込みを読み込むことができますが、私が更新しようとすると、それは先に既存の関連を削除しませんsee notes for .update()アソシエーションを介したウォーターラインアップデート

タグIDの配列を割り当てモデルに渡すことができるはずですが、現在の関連付けを削除して新しい関連付けを更新すると思います。

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

これは、ウォーターラインのレポで掲示された次の問題によって解決されました:https://github.com/balderdashy/waterline/issues/1453

+0

こんにちは、わかりやすく分かりやすいように、回答に詳細を追加してください。 – Chaithanya

+0

添付の問題をウォーターラインで見てください。このダイアログではすべて説明されています。 – Chase

+0

情報ありがとうございます。外部リソースへのリンクを提供することは有益ですが、解答自体にソリューションを提供し、参照のためにハイパーリンクを使用する方が良いでしょう。良い回答を書くためのヒントについては、http://stackoverflow.com/help/how-to-answerをご覧ください。 – Chaithanya

関連する問題