简体   繁体   中英

Get user relation users in parse query ionic4

I have the following parse query:

  loadAllFriends(params: any = {}): Promise<User[]> {
    const page = params.page || 0;
    const limit = params.limit || 20;
    const query = new Parse.Query(User);
    const user = Parse.User.current();
    const relation = user.relation('likes');
    query.equalTo('likes', user);

    query.descending('updatedAt');
    query.skip(page * limit);
    query.limit(limit);
    return query.find();
  }

...and i load the data in page.ts like:

 const users = await this.userService.loadAllFriends(this.params);
  console.log(users);
  for (let user of users) {
    this.users.push(user);
  }

... So this code it queries const user = Parse.User.current(); in likes relation column, checks if user is there and returns the results.

I need exact the opposite, with the anterior query i get the friends, but i need to get the followers. The followers are stored in user -> likes relation column:

在此处输入图像描述 在此处输入图像描述

How can i query user like:

 const user = Parse.User.current();
 query.equalTo('objectId', user.id);

... and here get the likes relation data from this user?

I don't think that you can do what you're trying to with a relation. I think that you'll need to model these relationships with a table:

{ fromUser, toUser, status }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM