Parse sort query via pointer

前端 未结 3 1464
伪装坚强ぢ
伪装坚强ぢ 2020-12-12 07:08

I need to do a simple query sort with Parse.

I have two classes: Captain and Boat. Every Captain has a Boat point

3条回答
  •  执笔经年
    2020-12-12 08:03

    There is a scalable solution for this, with rather minimal overhead: Currently you have a table of boats and a table of captains, where each captain contains a pointer to a boat.

    You should add a third table - let'c call it 'captains boats', which contains all the boats that are contained in a captain object. You maintain it by adding the boat when a new captain is added and by removing it from the table when a captain is deleted.

    In order to sort the captains by their boats:

    1. Query 'CaptainsBoats', sorted by whatever. Notice that even if this table contains a million records, you will get the first X that are relevant to you.
    2. Query 'Captains', use the 'containedIn' method with the boat list from step 1: [captainQuery whereKey:"boat" containedIn:boatList].

    3. Now you have only the captain objects you need (out of a possible million). Sort them locally according to whatever.

提交回复
热议问题