일부 구문 분석 데이터의 테이블에 일부 개체가 저장됩니다. 하지만 제약 조건을 추가하거나 삽입하려는 데이터가 고유해야합니다. 다음 코드와 같은 것을 사용하고 있습니다. 하지만 나는 (페이스 북 API에서 얻는) eventId가 내 테이블에서 고유하다는 것을 보증하기를 원하기 때문에 중복 정보가 없다. 작동하게하는 가장 좋은 방법은 무엇입니까?구문 분석 데이터의 열에 제약 조건 추가
var Event = Parse.Object.extend("Event");
var event = new Event();
event.set("eventId", id);
event.set("eventName", name);
event.save(null, {
success: function(event) {
console.log('New object created with objectId: ' + event.eventId);
},
error: function(event, error) {
console.log('Failed to create new object, with error code: ' + error.message);
}
});
업데이트 :
나는 HttpRequest를 내부를 호출하고 있습니다. 다음은 내가 가지고있는 것인데, 그 안의 beforeSave를 호출하는 방법을 알아낼 수 없다.
Parse.Cloud.define("hello", function(request, response) {
var query = new Parse.Query("Location");
query.find({
success: function(results) {
console.log(results);
var totalResults = results.length;
var completedResults = 0;
var completion = function() {
response.success("Finished");
};
for (var i = 0; i < totalResults; ++i){
locationId = results[i].get("locationFbId");
Parse.Cloud.httpRequest({
url: 'https://graph.facebook.com/v2.2/'+locationId+'/events?access_token='+accessToken,
success: function(httpResponse) {
console.log(httpResponse.data);
console.log("dsa"+locationId);
for (var key in httpResponse.data) {
var obj = httpResponse.data[key];
for (var prop in obj) {
var eventObj = obj[prop];
if (typeof(eventObj) === 'object' && eventObj.hasOwnProperty("id")) {
var FbEvent = Parse.Object.extend("FbEvent");
var fbEvent = new FbEvent();
fbEvent.set("startDate",eventObj["start_time"]);
fbEvent.set("locationFbId", locationId);
fbEvent.set("fbEventId", eventObj["id"]);
fbEvent.set("fbEventName", eventObj["name"]);
Parse.Cloud.beforeSave("FbEvent", function(request, response) {
var query = new Parse.Query("FbEvent");
query.equalTo("fbEventId", request.params.fbEventId);
query.count({
success: function(number) {
if(number>0){
response.error("Event not unique");
} else {
response.success();
}
},
error: function(error) {
response.error(error);
}
});
});
}
}
}
completedResults++;
if (completedResults == totalResults) {
completion();
}
},
error:function(httpResponse){
completedResults++;
if (completedResults == totalResults)
response.error("Failed to login");
}
});
}
},
error: function() {
response.error("Failed on getting locationId");
}
});
});
http://stackoverflow.com/questions/105034/create-guid-uuid-in-javascript 단지 세대 /이 GUID를 사용하여 반환하는 경우에만 저장. –
Srry, 나 didnt는 얻는다. 그리고 나는 내가 나의 질문에서 명백하지 않았다고 생각한다. ID는 페이스 북 API에 의해 주어집니다. 그래서이 ID를 생성하지 않습니다. – adolfosrs