1

Consider I have an object A having pointer to object B. Object B has a property "title" in it. I want to query on object A with a string which is contained in title of object B. Something like

var query1 = new Parse.Query("objectA");
query1.include("objectB");
query1.contains("objectB.title", anyQuery);
query.find({
          success: function(obj){
     },
     error: function(obj, error) {    
     }
});

"anyQuery" here can be any string entered by a user in search field. Consider a user inputs "Mary" as query I should get all objectA related to objectB having title containing "Mary" in it. For example "Maryland". Basically in simple words I want to execute a like query on related data in parse.

Edit

Thank you for the reply. I read the documentation at https://parse.com/docs/js_guide#queries-relational. I would like to extend my question. I want to use the query formed by matchesQuery in an or condition what I have done in my code is below but I get no results:

if(filterQuery) {
            var Organization = Parse.Object.extend("Organization");

            //LIKE QUERIES
            var nameLikeQuery = new Parse.Query(Parse.User);
            nameLikeQuery.contains("nameLc", filterQuery);  

            var phoneLikeQuery = new Parse.Query(Parse.User);
            phoneLikeQuery.contains("phone", filterQuery);      

            var emailLikeQuery = new Parse.Query(Parse.User);
            emailLikeQuery.contains("username", filterQuery);

            var organizationMatchQuery = new Parse.Query(Organization);         
            organizationMatchQuery.contains("titleLc", filterQuery);    

            var userOrganizationQuery = new Parse.Query(Parse.User);
            userOrganizationQuery.matchesQuery("organization", organizationMatchQuery);

            var userQuery1 = new Parse.Query.or(nameLikeQuery, phoneLikeQuery);
            var userQuery2 = new Parse.Query.or(emailLikeQuery, userQuery1);

            userQuery = new Parse.Query.or(userQuery2, userOrganizationQuery);
        } else {
            userQuery = new Parse.Query(Parse.User);
        }       
        if(type != "ALL") {
            userQuery.equalTo("userType", type);
        }
        userQuery.include("organization");
        userQuery.descending("createdAt");
        userQuery.find();
5
  • What are you comparing objectB.title to? Aug 5, 2014 at 5:46
  • Oops! Sorry. Its query1.contains("objectB.title", anyQuery); But this doesn't work. I want to know the right syntax for the same. Please help me with the same.
    – XCEPTION
    Aug 5, 2014 at 10:24
  • Edit your question to make it accurate then, but also tell us what anyQuery is or means. Aug 5, 2014 at 10:30
  • I have edited my question. I hope it is understandable now. Sorry for bad question structure.
    – XCEPTION
    Aug 5, 2014 at 11:01
  • This use case appears well documented under relational queries in the parse documentation. parse.com/docs/js_guide#queries-relational See matchesQuery Aug 5, 2014 at 11:16

1 Answer 1

1

As stated by Chris, this scenario is well documented under Relational Queries here:

https://parse.com/docs/js_guide#queries-relational

So for your particular needs it would look like:

var objectBQuery = new Parse.Query("objectB");
objectBQuery.contains("title", anyString);
var objectAQuery = new Parse.Query("objectA");
objectAQuery.matchesQuery("objectB", objectBQuery);
objectAQuery.find().then(function (list) {
    // use list
}, function (error) {
    console.log(error);
});

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.