title: How to Query One-to-Many Relationship in Parse Server using Swift
body: <p>I am trying to build a chat app in Parse using Swift. At viewDidLoad I want to query Dashboard for new messages. I do that with below code but don’t get any results and parse does not give me any error. As Parse does not know joins, how can I fetch the Chat data based on a subquery ?</p>
  
  <p>My plan is to do something like this:</p>
  
  <pre><code>Select * from Chat inner join ChatMember where chat.objectId =  ChatMember.chatId and user = &lt;current user&gt;
  </code></pre>
  
  <p>Code</p>
  
  <pre><code>    let squery = PFQuery(className: "ChatMember")
      squery.whereKey(“user”, equalTo:(PFUser.current())!)
  
  
      let query = PFQuery(className: "Chat")
      query.whereKey("chatId", matchesQuery: squery)
  
      // tried it with this one too, but same result
  
      query.whereKey("objectId", matchesKey:"chatId", in: squery)
  </code></pre>
  
  <p>Data Structure</p>
  
  <pre><code>Class Chat {objectId: String, owner: Pointer _User, name: String,    lastActivity: Date}
  
  Class ChatMember {objectId: String, chatId: Pointer Chat, user: Pointer _User, memberSince: Date,  lastActivity: Date, Mute: Boolean}
  
  Class Message {objectId: String, chatId: Pointer Chat, author: Pointer _User, createAt: Date, message: String }
  </code></pre>
  
  <p>Tests I already did:</p>
  
  <p>The fields in the database are correct. Because if I add a new column to ChatMember and store the chat id as string it works perfectly. Just not with the pointer:</p>
  
  <pre><code>let squery = PFQuery(className: "ChatMember")
  squery.whereKey(“user”, equalTo:(PFUser.current())!)
  
  
  let query = PFQuery(className: "Chat")
  query.whereKey("objectId", matchesKey:"CHATID_AS_STRING", in: squery)
  </code></pre>