Parse: How do I query using PFRelation when I just have PFUser?

前端 未结 1 638
半阙折子戏
半阙折子戏 2020-12-21 18:27

Here is an example of what I am trying to do. I have the current user as PFUser and on another class named Item I have a relation named \"owners\" which is a relation of PFU

1条回答
  •  北海茫月
    2020-12-21 19:11

    You can use whereKey:equalTo: on a relation column and pass it a PFObject. This query will then return all Teacher objects which have this student in their "students" relation:

    PFQuery *query = [PFQuery queryWithClassName:@"Teacher"]; [query whereKey:@"students" equalTo:student];

    In this example, the student is a PFObject with a className that matches the relation in "students". If this is a relation of PFUsers and you're looking for the current user's "Teacher"s, you'd use:

    PFQuery *query = [PFQuery queryWithClassName:@"Teacher"]; [query whereKey:@"students" equalTo:[PFUser currentUser]];

    This answer also posted on Parse's community forums: https://parse.com/questions/how-do-i-query-using-pfrelation-when-i-just-have-pfuser

    0 讨论(0)
提交回复
热议问题