2017-04-12 8 views
0

Sail 관련된 개체를 추가 한 후 다 대다 연관 관계가 저장 될 때 오류가 발생합니다. 여기 내 모델링입니다.연관된 개체에 레코드 추가 throw 및 오류 many-to-many 워터 라인 돛

User: 

module.exports = { 
    attributes: { 
    ... 
    operations: { 
     collection: 'operation', 
     via: 'users' 
    } 
    } 
}; 

작업 : 내 사용자의 컨트롤러에

module.exports = { 
    attributes: { 
    ... 
    users: { 
     collection: 'users', 
     via: 'operations', 
    } 
    } 
}; 

, 내가 가진 :

여기
addPermissionToUsers: function(req, res) { 
     Users.findOne(2).populate('operations').exec(function (err, user) { 

      if (err) throw err// handle error 
       // Queue up a record to be inserted into the join table 
       user.operations.add(1); 
      Save the user, creating the new associations in the join table 
      user.save(function (err) {  
       if (err) throw err 
        res.json(user) 
      }); 
     }); 
    } 

오류 추적 있습니다 :

  if (err) throw err 
         ^
Error (E_UNKNOWN) :: Encountered an unexpected error 
    at new WLError (/usr/local/lib/node_modules/sails/node_modules/waterline/lib/waterline/error/WLError.js:25:15) 
    at /usr/local/lib/node_modules/sails/node_modules/waterline/lib/waterline/model/lib/defaultMethods/save.js:188:17 
    at /usr/local/lib/node_modules/sails/node_modules/waterline/node_modules/async/lib/async.js:52:16 
    at /usr/local/lib/node_modules/sails/node_modules/waterline/node_modules/async/lib/async.js:550:17 
    at /usr/local/lib/node_modules/sails/node_modules/waterline/node_modules/async/lib/async.js:544:17 
    at _arrayEach (/usr/local/lib/node_modules/sails/node_modules/waterline/node_modules/async/lib/async.js:85 
+0

'사용자'모델이 있습니까? – Sangharsh

+0

예, 사용자가 있습니다. –

+0

아니'사용자', 당신은'사용자'모델이 있습니까? 이 줄 ('collection : 'users',')는'User' 대신'Users' 모델을 참조합니다. – Sangharsh

답변

0

세상에! 이 문제에 직면 한 사람이라면 돛이 자동으로 조인트 테이블을 만들 수 있도록 마이그레이션을 실행하면됩니다. 나에게 config/model.js를 migrate: 'drop'으로 변경하고 돛에 접합 테이블을 추가하면 매력처럼 작동합니다.