1

I have two related objects (Shop and Item). Item object has a field containing its Shop object.

How to create a parseQuery to get all shops having at least one item.

Manuel
  • 14,274
  • 6
  • 57
  • 130
Elnaz
  • 476
  • 1
  • 5
  • 7

1 Answers1

1

You have to write a cloud code Elnaz jan and then query there. Something like this below. However, first put a column as itemNumber with a 0 value. When a new item is saved then change that one to 1. This way you will know on your return that there should be an item there. I think with the SDK you can query in your own code without haing to go to cloud code. Either way works.

Parse.Cloud.define("getFeatured", function(request, response) {
  var query = new Parse.Query("allCars");
  query.equalTo("itemNumber", 1) ;
  query.find({
    success: function(results) {
      response.success(results);
    },
    error: function() {
      response.error("lookup failed");
    }
  });
});
Amir
  • 1,667
  • 3
  • 23
  • 42
  • Thank you Amir. But I was looking for a way without a new field for shop object to keep track of items count. – Elnaz Mar 23 '16 at 13:16
  • I actually did something like this where a user had several contacts and needed to know how many are there. I think it is easier if you add a columns and keep the count of the items. I can send you something like that later. You can use also "query.greaterThan" instead of equal. Are you good in parse.com? They are going to discontinue the service anyway. If your app is not big I found a way to work with Google Spreadsheet to work as your database. – Amir Mar 24 '16 at 03:36
  • Thank you Amir. Yea I know Parse gonna stop its service. But I had an on-hand project based on it and have to finish it then migrate to something else . Thank you for your help about migrating but I might migrate to some other possible server languages. – Elnaz Mar 24 '16 at 08:35
  • No worries Elnaz. Ask me questions on Linkedin https://www.linkedin.com/in/amirfarazmand – Amir Mar 24 '16 at 11:56