2014-11-17 5 views
0

두 개의 편집증 표 (사용자 및 전자 메일) 사이에 관계가 있고 onDelete : 관계에 대한 '계단식'옵션이 있습니다 (Email.belongsTo (사용자, onDelete : '계단식')) .편집증 표에 계단식 삭제 - Sequelize

문제는 사용자를 삭제할 때 그의 이메일이 이 아니고 캐스케이드로 인해이 삭제된다는 것입니다.

내가 실수를했거나 sequelize에 버그가 있습니까?

나는 postgres 데이터베이스에서 2.0.0-rc2을 후속 사용하고 있습니다.

감사합니다.

추신 : 내가 시험에 사용되는 코드에서 봐 주시기 바랍니다 :

var Sequelize = require('sequelize') 
    , sequelize = new Sequelize('test', 'test', 'test', {dialect: 'postgres'}); 

var User = sequelize.define('User', { 
    username: Sequelize.STRING, 
    birthday: Sequelize.DATE 
}, {paranoid: true}); //Without paranoid the code works fine 

var Email = sequelize.define('Email', { 
    email: Sequelize.STRING, 
    primary: Sequelize.BOOLEAN 
}, {paranoid: true}); //Without paranoid the code works fine 

Email.belongsTo(User, {onDelete: 'cascade'}); 

sequelize.sync().success(function() { 
    var userCreatedInstance = null; 

    var deletedUserId = null; 
    var cascadeDeletedEmailId = null; 

    User 
     .create({ 
      username: 'user1', 
      birthday: new Date(1986, 06, 28) 
     }) 
     .then(function (_user) { 
      userCreatedInstance = _user; 
      deletedUserId = userCreatedInstance.id; 
      return Email.create({email: '[email protected]', primary: true, UserId: userCreatedInstance.id}); 
     }) 
     .then(function (createdEmail) { 
      cascadeDeletedEmailId = createdEmail.id; 
      return userCreatedInstance.destroy(); 
     }) 
     .then(function() { 
      return User.find(deletedUserId); 
     }) 
     .then(function (foundUser) { 
      if(foundUser){ 
       throw new Error("Shouldn't find the user with this id"); 
      } 
      return Email.find(cascadeDeletedEmailId); 
     }) 
     .then(function (foundEmail){ 
      if(foundEmail){ 
       console.log(foundEmail.values); 
       throw new Error("Shouldn't find the email with this id"); 
      } 
     }); 
}); 

답변

0

내가 캐스케이드 옵션은 데이터베이스 캐스케이드 옵션을 설정하는 것을 알아 냈다. sequelize를 통해 삭제되는 캐스케이드는 없습니다.

그러나 sequelize 팀은 향후 편집증 환자를위한 캐스 캐 이드 작업을 수행 할 예정입니다.

공개 문제는 https://github.com/sequelize/sequelize/issues/2586

입니다.