2012-03-15 3 views
0

Sequelize JS를 사용하여 행을 삭제하거나 업데이트하려고 할 때 문제가 발생합니다. 내가 (업데이트에 대한) 같은 것을 할 때 :Sequelize j에서 업데이트 및 삭제시 문제

Embed.find(parseInt(req.body.id, 10)).success(function(embed) { 
    embed.updateAttributes({ 
     NOME : req.body.name, 
     EMBED : req.body.embed 
    }).success(function() { 
     res.json({"success" : true}); 
    }).error(function() { 
     res.json({"success" : false}); 
    }); 
}); 

또는 (삭제에) : 그것은 오류를 보여

Embed.find(parseInt(req.body.id, 10)).success(function(embed){ 
    embed.destroy().success(function(e) { 
     console.log(e); 
     if(e && e.deletedAt) { 
      res.json({"success": true}); 
     } 
    }).error(function(e){ 
     console.log(e); 
    }); 
}).error(function(){ 
    res.json({"success": false}); 
}); 

을 :

return (typeof obj == 'object') && !obj.hasOwnProperty('length') 

형식 오류 : 호출 할 수 없습니다 메서드 'hasOwnProperty'of null null at Object.isHash

누구도 kn 무슨 일이 일어나고있는거야?

+0

어떤 버전을 사용하고 있습니까? 두 번째 줄에 무엇이 포함되어 있습니까? – sdepold

+0

안녕하세요. 1.3.7 버전을 사용하고 있습니다. "embed"는 find 메소드의 답변 일 것입니다 (올바른 행을 반환 함). –

답변

1

내가 틀렸다고 생각합니다. find() 메서드를 사용하는 경우에는 그 안에 개체를 전달해야합니다. 다음과 같이;

Embed 
    .findAll({ "id": parseInt(req.body.id) }) 
    .then(function(embed) { ... }); 

그리고이 코드는 promise로부터 배열을 반환합니다. 따라서 직접 embed.updateAttributes(...)으로 사용할 수 없습니다. 이런 식으로 사용해야합니다. embed[0].updateAttributes(...).

또는 다음과 같이 사용할 수 있습니다.

Embed 
    .findOne({ "id": parseInt(req.body.id) }) 
    .then(function(embed) { embed.updateAttributes(...); }); 

findOne()은 발견 한 객체 만 반환합니다.

그리고 .. 지금 나는이 지위가 매우 오래된 것을 보았습니다. 그리고 .find() 메소드는 더 이상 사용되지 않습니다. 그래서 나는 방법을 findAll()으로 바꿨다. 나는 이것들이 같은 과정을하고 있다고 생각한다.