1

For my Android app, I have subclassed ParseObject to create Food, Pref classes and CustomUser class which extends ParseUser and created a relation "lovers" between 'Food' and 'Users'.

Inside a CustomUser object, I have stored an Pref object using createWithoutData method in key "pref".CustomUser and its respective Pref object have one-to-one mapping

So when I want to display all lovers of a particular food in a listview using ParseQueryAdapter,

ParseQueryAdapter<ParseObject> adapter = new ParseQueryAdapter<ParseObject>(getActivity(),
    new ParseQueryAdapter.QueryFactory<ParseObject>() {
        public ParseQuery<ParseObject> create() {
               ParseQuery<ParseObject> query = food.getRelation("lovers").getQuery();
               query.selectKeys(Arrays.asList("pref");                                      
               return query;
        }
    });

adapter.setTextKey(Pref.COLUMN_PROFILE_NAME); adapter.setImageKey(Pref.COLUMN_PROFILE_PIC_THUMB);

fyi, COLUMN_PROFILE_NAME = "profileName", COLUMN_PROFILE_PIC_THUMB = "profileThumb"

Now the problem is that "pref" is only a reference to the actual object. So when the listView tries to get text and image, it says "ParseObject has no data for this key. Call fetchIfNeeded() to get the data"

My objective is to pass a query to ParseQueryAdapter that will fetch all pref objects nested inside CustomUsers having 'lovers' relation with that particular food.

The parse docs say that 'include' method does not work on relations.

Please help, I have been struggling on this for long now.

4

2 回答 2

1

要检索关系,我不相信您可以使用查询。在你的情况下,你会使用

ParseRelation<ParseObject> relation = user.getRelation("lovers");

请参阅本文档

希望这可以帮助

于 2013-10-25T15:38:47.080 回答
0

下面是一个展示此类可用配置级别的示例:

// Instantiate a QueryFactory to define the ParseQuery to be used for fetching items in this
 // Adapter.
 ParseQueryAdapter.QueryFactory<ParseObject> factory =
     new ParseQueryAdapter.QueryFactory<ParseObject>() {
       public ParseQuery create() {
         ParseQuery query = new ParseQuery("Customer");
         //query.whereEqualTo("activated", true);
         //query.orderByDescending("moneySpent");
     query.include("your key");

         return query;
       }
     };

 // Pass the factory into the ParseQueryAdapter's constructor.
 ParseQueryAdapter<ParseObject> adapter = new ParseQueryAdapter<ParseObject>(this, factory);
 adapter.setTextKey("name");

 // Perhaps set a callback to be fired upon successful loading of a new set of ParseObjects.
 adapter.addOnQueryLoadListener(new OnQueryLoadListener<ParseObject>() {
   public void onLoading() {
     // Trigger any "loading" UI
   }

   public void onLoaded(List<ParseObject> objects, ParseException e) {
     // Execute any post-loading logic, hide "loading" UI
   }
 });

 // Attach it to your ListView, as in the example above
 ListView listView = (ListView) findViewById(R.id.listview);
 listView.setAdapter(adapter);
于 2014-06-05T20:44:16.300 回答