1

How to get all posts (Post) that have images (Relation) in android Parse

My code

// get their postsList
ParseQuery<Post> query = new ParseQuery<Post>(Post.class);
query.orderByDescending("views");
query.whereExists("images"); // only post with images attached to
query.include("User.profileImage.image");
query.whereEqualTo("isPublic", true);
posts = query.find();

I need to exclude any post that has zero images.

in another words, how to get posts whose images column is Relation with a size of 1 or more

Community
  • 1
  • 1
Hatim
  • 1,516
  • 1
  • 18
  • 30

1 Answers1

0

I've one class that is a little like your reported case, but I'll send for you using JS code, at Parse Server, you can upload it at your Cloud Code. Back4App makes available in your features to upload the file in: Server Settings> Cloud code section> Settings or you can use the CLI to upload the files (Command Line Interface), the code to check if the image have relation is:

var Images = Parse.Object.extend("Image");
var query = new Parse.Query(Images);
var object;

query.doesNotExist("image");
query.doesNotExist("picture");

query.find()
.then(function(results) {
    for (var i = 0; i < results.length; i++) {
        object = results[i];
        console.log(object.id);
    }
});

At Parse Server Docs, you have a guide to Android, I checked here, will be something like:

query.whereDoesNotExist("image");

If you want to include more columns at yout logic, just insert it before call the find() method :)

nataliec
  • 502
  • 4
  • 14
  • in fact, whereDoesNotExist and whereExists works with ParseObject, but not with ParseRelation.. my 'images' column is ParseRelation – Hatim Apr 29 '18 at 01:20
  • Hi, thanks for your reply! Did you already checked the link from Parse Server Docs about relational data? http://docs.parseplatform.org/android/guide/#relational-data – nataliec May 01 '18 at 15:34