2014-07-01 3 views
0

게시물의 수명이 제한되는 애플리케이션이 있습니다. 모든 것은 게시물에 생명을 불어 넣습니다.Parse.com : 다른 쿼리의 결과로 쿼리

내 테이블 내 필드 initialDeletionDate 및 좋아하는 수를 추적하는 카운터가 있습니다. 내 뉴스 피드에서 객체를 쿼리하려고하는데 아직 살아있는 객체 만 가져 오려고합니다.

그래서 기본적으로 내가하고 싶은 모든 객체를 얻을입니다 :

initialDeletionDate + counter*time < [NSDate date] 
//time = 1200 sec 

뭔가 같은 ... :

[query whereKey:@"initialDeletionDate" lessThan:[NSDate date] - "key: counter"]; 

내가 어떻게 할 수 있습니까?

답변

1

최종 삭제 날짜가있는 클래스에 세 번째 필드를 추가하는 것이 좋습니다. 클라이언트 코드를 업데이트하거나이 날짜의 값을 initialDeletionDate + (counter*1200)으로 설정하는 클라우드 메서드를 만들 수 있습니다.

그런 다음 당신은 당신이 아직 자신의 계산 삭제 날짜에 도달하지 않은 기록을 요청할 수 있습니다 쿼리 할 때 :

[query whereKey:@"calculatedDeletionDate" greaterThan:[NSDate date]]; 

업데이트 :

여기 사전이 저장 클라우드 기능을위한 출발점입니다.

// include Moment library for easier date handling 
var moment = require("moment"); 

Parse.Cloud.beforeSave("YourClassNameHere", function(request, response) { 
    var yourClass = request.object; 

    if (yourClass.dirty("initialDeletionDate") 
     || yourClass.dirty("counter")) 
    { 
     // recalculate 
     var initialDate = yourClass.get("initialDeletionDate"); 
     var counter = yourClass.get("counter"); 
     // use Moment library to manipulate the date 
     var calculatedDate = moment(initialDate) 
      .add('minutes', counter * 2) 
      .toDate(); 
     yourClass.set("calculatedDeletionDate", calculatedDate); 
    } 
    response.success(); 
} 
+0

답변을 주신 Timothy에게 감사드립니다. iOs 클라이언트에서 cloudcode 메소드를 호출합니까? 여러 사용자가 동시에 카운터를 증가 시키면 "calculatedDeletionDate"가 정확합니까? –

+0

@SanchoSanchez 저장하기 전 클라우드 기능을 만들면 계산이 올바르게 업데이트되도록 유지할 수 있습니다. –

+0

에 대한 답변을 샘플로 추가해 드리겠습니다. –

관련 문제