2013-12-19 4 views
1

구문 분석에 두 테이블을 포함하는 데이터베이스 스키마가 있습니다. 연락처 & contactRelationships.구문 분석에서 포인터가있는 개체 검색

Contacts 
userid: 1, username: Bob 
userid: 2, username: Alice 
userid: 3, username: Chris 


ContactRelationships 
friend_A: 1, friend_B: 2 --> Bob and Alice are friends 
friend_A: 2, friend_B: 3 --> Alice and Chris are friends 

내가 같은 쿼리를 구성하려면 :

연락처는 연락처 목록을 포함, contactRelationships은 관계, 즉 형성하기 위해 함께 사용자를 묶어 "SELECT * ContactRelationships FROM을 WHERE friend_A = 1 AND friend_B = 2 ".

지금 당장 가지고있는 문제는 연락처에 포인터을 저장하고 있는데 쿼리를 생성하려고하는데 포인터가 로컬 데이터에 저장되어 있지 않습니다. (핵심 데이터). 사용자 ID 만 저장했습니다.

포인터 대신 사용자 ID 문자열을 저장하도록 데이터베이스를 변경하지 않고도이 작업을 수행 할 수 있습니까?

답변

3

어쩌면이 대답은 쿼리와 함께 당신을 도울 수 있습니다 Parse.com: Find all objects belonging to a user with objectId

는 기본적으로 대신 포인터 만 가져다의 중첩 된 개체를 포함하는 쿼리를 설정해야합니다. 원하는 사용자 객체를 만들고 객체 ID 대신 전체 객체를 비교할 수 있습니다.

// Create your query and set which nested objects you want 
var query = new Parse.Query('ContactRelationships'); 
query.include('friend_A'); 
query.include('friend_B'); 

// Create local instances of your user objects 
var userA = new Parse.User(); 
userA.id = 1; 
var userB = new Parse.User(); 
userB.id = 2; 

// Query your database comparing objects 
query.equalTo('friend_A', fetchedUserA); 
query.equalTo('friend_B', fetchedUserB); 
query.find({ 
    success: function(result) { 
     // Do your thing here 
    } 
}); 
을 : 나는 언어를 당신이 코드는 다음과 같이 할 수 프로그래밍하지만 클라우드 코드 (자바 스크립트)에 모르는

관련 문제