node.js - Sails.js How to insert data into a join table (Many to Many) -


i having error inserting data join table , don't know if i'm doing right way. here 2 models have many many association.

commit.js:

module.exports = {   schema: true,   attributes: {     idcommit : {       type: 'integer',       autoincrement: true,       primarykey: true,       unique: true     },     revision : {     type: 'integer',     required: true     },     issues: {       collection: 'issue',       via: 'commits',       dominant: true     }   } }; 

issue.js:

module.exports = {   schema: true,   attributes: {     idissue : {       type: 'integer',       autoincrement: true,       primarykey: true,       unique: true     },     description: {     type: 'string',     required: true     },     commits: {       collection: 'commit',       via: 'issues'     }   } }; 

when try insert issues commit way :

commit.create(commit).exec(function(err,created){   if (err) {     console.log(err);   }   else {      created.issues.add(issues);     created.save(function(err) {});   } }); 

my commit created, issues created, there no link ever between them , join table stays empty. did wrong?

from code looks trying add array of issues, try doing association individually, in many-to-many docs

commit.create(commit).exec(function(err,created){   if (err) {     console.log(err);   }   else {       issues.foreach(function(issue, index){         created.issues.add(issue);     })      created.save(function(err) {});   } }); 

Comments

Popular posts from this blog

javascript - AngularJS custom datepicker directive -

javascript - jQuery date picker - Disable dates after the selection from the first date picker -