Query on pointer in parse.com Objects in Javascript











up vote
11
down vote

favorite












I have a Class of Company which has User pointers. The query I want on Company class is like this:



Retrieve Company rows where User object has a name equal to 'ABC'



So, how should I form this query ?



var Company = Parse.Object.extend("Company");
var query = Parse.Query(Company);
query.include("User");

query.equalTo("name") ????


Is it possible to write such a request in a single query ?
Thanks.










share|improve this question


























    up vote
    11
    down vote

    favorite












    I have a Class of Company which has User pointers. The query I want on Company class is like this:



    Retrieve Company rows where User object has a name equal to 'ABC'



    So, how should I form this query ?



    var Company = Parse.Object.extend("Company");
    var query = Parse.Query(Company);
    query.include("User");

    query.equalTo("name") ????


    Is it possible to write such a request in a single query ?
    Thanks.










    share|improve this question
























      up vote
      11
      down vote

      favorite









      up vote
      11
      down vote

      favorite











      I have a Class of Company which has User pointers. The query I want on Company class is like this:



      Retrieve Company rows where User object has a name equal to 'ABC'



      So, how should I form this query ?



      var Company = Parse.Object.extend("Company");
      var query = Parse.Query(Company);
      query.include("User");

      query.equalTo("name") ????


      Is it possible to write such a request in a single query ?
      Thanks.










      share|improve this question













      I have a Class of Company which has User pointers. The query I want on Company class is like this:



      Retrieve Company rows where User object has a name equal to 'ABC'



      So, how should I form this query ?



      var Company = Parse.Object.extend("Company");
      var query = Parse.Query(Company);
      query.include("User");

      query.equalTo("name") ????


      Is it possible to write such a request in a single query ?
      Thanks.







      javascript parse.com cloud-code






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 14 '14 at 4:56









      Yatin Mehandiratta

      632620




      632620
























          4 Answers
          4






          active

          oldest

          votes

















          up vote
          13
          down vote













          You'll need to query for the User first based on the name of "ABC". Then in the success callback of that query, do the query on your Company table using the objectId returned from the User query. Something like this:



          var userQuery = Parse.Query('_User');
          var companyQuery = Parse.Query('Company');

          userQuery.equalTo('name', 'ABC');

          userQuery.find({
          success: function(user) {
          var userPointer = {
          __type: 'Pointer',
          className: '_User',
          objectId: user.id
          }

          companyQuery.equalTo('user', userPointer);

          companyQuery.find({
          success: function(company) {
          // WHATEVER
          },
          error: function() {
          }
          });
          },
          error: function() {
          }
          });





          share|improve this answer





















          • Hi, thanks for answering.. I asked because I needed to know if this is possible in a single query.. Similar to inner queries in MySql.
            – Yatin Mehandiratta
            Dec 1 '14 at 7:04






          • 1




            Thanks man very helpful !
            – Muhammad Awais
            Sep 7 '15 at 5:30










          • It's very awkward to have to create a pointer element, but that does work. Thank you for this.
            – DiamondDrake
            Apr 8 '17 at 22:35


















          up vote
          8
          down vote













          You can use an inner query:



          var Company = Parse.Object.extend("Company");
          var mainQuery = Parse.Query(Company);

          var UserObject = Parse.Object.extend("User");
          var innerUserQuery = new Parse.Query(UserObject);
          innerBankQuery.equalTo("name", "ABC");
          mainQuery.matchesQuery("bank", innerBankQuery);

          var ansCollection = mainQuery.collection();
          ansCollection.fetch({
          success: function(results) {
          // Do whatever ...
          }
          });





          share|improve this answer





















          • What is innerBankQuery in your example?
            – Neil Galiaskarov
            Jun 10 at 9:51


















          up vote
          2
          down vote













          I should say the query will be...



          const userQuery = Parse.Query('_User');

          userQuery.equalTo('name', 'ABC');

          userQuery.find().then((user) => {

          const companyQuery = Parse.Query('Company');

          companyQuery.equalTo('user', {
          __type: 'Pointer',
          className: '_User',
          objectId: user.id
          });

          companyQuery.find().then((company) => {
          console.log(company);
          });
          });





          share|improve this answer




























            up vote
            0
            down vote













            Assuming Your Company collection has a field called User and User collection has a name field, then you can search for Company with user name through
            companyQuery.equalTo("User.name");



            This works in Parse 2.1.0






            share|improve this answer























              Your Answer






              StackExchange.ifUsing("editor", function () {
              StackExchange.using("externalEditor", function () {
              StackExchange.using("snippets", function () {
              StackExchange.snippets.init();
              });
              });
              }, "code-snippets");

              StackExchange.ready(function() {
              var channelOptions = {
              tags: "".split(" "),
              id: "1"
              };
              initTagRenderer("".split(" "), "".split(" "), channelOptions);

              StackExchange.using("externalEditor", function() {
              // Have to fire editor after snippets, if snippets enabled
              if (StackExchange.settings.snippets.snippetsEnabled) {
              StackExchange.using("snippets", function() {
              createEditor();
              });
              }
              else {
              createEditor();
              }
              });

              function createEditor() {
              StackExchange.prepareEditor({
              heartbeatType: 'answer',
              convertImagesToLinks: true,
              noModals: true,
              showLowRepImageUploadWarning: true,
              reputationToPostImages: 10,
              bindNavPrevention: true,
              postfix: "",
              imageUploader: {
              brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
              contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
              allowUrls: true
              },
              onDemand: true,
              discardSelector: ".discard-answer"
              ,immediatelyShowMarkdownHelp:true
              });


              }
              });














               

              draft saved


              draft discarded


















              StackExchange.ready(
              function () {
              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f26923172%2fquery-on-pointer-in-parse-com-objects-in-javascript%23new-answer', 'question_page');
              }
              );

              Post as a guest















              Required, but never shown

























              4 Answers
              4






              active

              oldest

              votes








              4 Answers
              4






              active

              oldest

              votes









              active

              oldest

              votes






              active

              oldest

              votes








              up vote
              13
              down vote













              You'll need to query for the User first based on the name of "ABC". Then in the success callback of that query, do the query on your Company table using the objectId returned from the User query. Something like this:



              var userQuery = Parse.Query('_User');
              var companyQuery = Parse.Query('Company');

              userQuery.equalTo('name', 'ABC');

              userQuery.find({
              success: function(user) {
              var userPointer = {
              __type: 'Pointer',
              className: '_User',
              objectId: user.id
              }

              companyQuery.equalTo('user', userPointer);

              companyQuery.find({
              success: function(company) {
              // WHATEVER
              },
              error: function() {
              }
              });
              },
              error: function() {
              }
              });





              share|improve this answer





















              • Hi, thanks for answering.. I asked because I needed to know if this is possible in a single query.. Similar to inner queries in MySql.
                – Yatin Mehandiratta
                Dec 1 '14 at 7:04






              • 1




                Thanks man very helpful !
                – Muhammad Awais
                Sep 7 '15 at 5:30










              • It's very awkward to have to create a pointer element, but that does work. Thank you for this.
                – DiamondDrake
                Apr 8 '17 at 22:35















              up vote
              13
              down vote













              You'll need to query for the User first based on the name of "ABC". Then in the success callback of that query, do the query on your Company table using the objectId returned from the User query. Something like this:



              var userQuery = Parse.Query('_User');
              var companyQuery = Parse.Query('Company');

              userQuery.equalTo('name', 'ABC');

              userQuery.find({
              success: function(user) {
              var userPointer = {
              __type: 'Pointer',
              className: '_User',
              objectId: user.id
              }

              companyQuery.equalTo('user', userPointer);

              companyQuery.find({
              success: function(company) {
              // WHATEVER
              },
              error: function() {
              }
              });
              },
              error: function() {
              }
              });





              share|improve this answer





















              • Hi, thanks for answering.. I asked because I needed to know if this is possible in a single query.. Similar to inner queries in MySql.
                – Yatin Mehandiratta
                Dec 1 '14 at 7:04






              • 1




                Thanks man very helpful !
                – Muhammad Awais
                Sep 7 '15 at 5:30










              • It's very awkward to have to create a pointer element, but that does work. Thank you for this.
                – DiamondDrake
                Apr 8 '17 at 22:35













              up vote
              13
              down vote










              up vote
              13
              down vote









              You'll need to query for the User first based on the name of "ABC". Then in the success callback of that query, do the query on your Company table using the objectId returned from the User query. Something like this:



              var userQuery = Parse.Query('_User');
              var companyQuery = Parse.Query('Company');

              userQuery.equalTo('name', 'ABC');

              userQuery.find({
              success: function(user) {
              var userPointer = {
              __type: 'Pointer',
              className: '_User',
              objectId: user.id
              }

              companyQuery.equalTo('user', userPointer);

              companyQuery.find({
              success: function(company) {
              // WHATEVER
              },
              error: function() {
              }
              });
              },
              error: function() {
              }
              });





              share|improve this answer












              You'll need to query for the User first based on the name of "ABC". Then in the success callback of that query, do the query on your Company table using the objectId returned from the User query. Something like this:



              var userQuery = Parse.Query('_User');
              var companyQuery = Parse.Query('Company');

              userQuery.equalTo('name', 'ABC');

              userQuery.find({
              success: function(user) {
              var userPointer = {
              __type: 'Pointer',
              className: '_User',
              objectId: user.id
              }

              companyQuery.equalTo('user', userPointer);

              companyQuery.find({
              success: function(company) {
              // WHATEVER
              },
              error: function() {
              }
              });
              },
              error: function() {
              }
              });






              share|improve this answer












              share|improve this answer



              share|improve this answer










              answered Dec 1 '14 at 1:30









              jeffdill2

              2,79521638




              2,79521638












              • Hi, thanks for answering.. I asked because I needed to know if this is possible in a single query.. Similar to inner queries in MySql.
                – Yatin Mehandiratta
                Dec 1 '14 at 7:04






              • 1




                Thanks man very helpful !
                – Muhammad Awais
                Sep 7 '15 at 5:30










              • It's very awkward to have to create a pointer element, but that does work. Thank you for this.
                – DiamondDrake
                Apr 8 '17 at 22:35


















              • Hi, thanks for answering.. I asked because I needed to know if this is possible in a single query.. Similar to inner queries in MySql.
                – Yatin Mehandiratta
                Dec 1 '14 at 7:04






              • 1




                Thanks man very helpful !
                – Muhammad Awais
                Sep 7 '15 at 5:30










              • It's very awkward to have to create a pointer element, but that does work. Thank you for this.
                – DiamondDrake
                Apr 8 '17 at 22:35
















              Hi, thanks for answering.. I asked because I needed to know if this is possible in a single query.. Similar to inner queries in MySql.
              – Yatin Mehandiratta
              Dec 1 '14 at 7:04




              Hi, thanks for answering.. I asked because I needed to know if this is possible in a single query.. Similar to inner queries in MySql.
              – Yatin Mehandiratta
              Dec 1 '14 at 7:04




              1




              1




              Thanks man very helpful !
              – Muhammad Awais
              Sep 7 '15 at 5:30




              Thanks man very helpful !
              – Muhammad Awais
              Sep 7 '15 at 5:30












              It's very awkward to have to create a pointer element, but that does work. Thank you for this.
              – DiamondDrake
              Apr 8 '17 at 22:35




              It's very awkward to have to create a pointer element, but that does work. Thank you for this.
              – DiamondDrake
              Apr 8 '17 at 22:35












              up vote
              8
              down vote













              You can use an inner query:



              var Company = Parse.Object.extend("Company");
              var mainQuery = Parse.Query(Company);

              var UserObject = Parse.Object.extend("User");
              var innerUserQuery = new Parse.Query(UserObject);
              innerBankQuery.equalTo("name", "ABC");
              mainQuery.matchesQuery("bank", innerBankQuery);

              var ansCollection = mainQuery.collection();
              ansCollection.fetch({
              success: function(results) {
              // Do whatever ...
              }
              });





              share|improve this answer





















              • What is innerBankQuery in your example?
                – Neil Galiaskarov
                Jun 10 at 9:51















              up vote
              8
              down vote













              You can use an inner query:



              var Company = Parse.Object.extend("Company");
              var mainQuery = Parse.Query(Company);

              var UserObject = Parse.Object.extend("User");
              var innerUserQuery = new Parse.Query(UserObject);
              innerBankQuery.equalTo("name", "ABC");
              mainQuery.matchesQuery("bank", innerBankQuery);

              var ansCollection = mainQuery.collection();
              ansCollection.fetch({
              success: function(results) {
              // Do whatever ...
              }
              });





              share|improve this answer





















              • What is innerBankQuery in your example?
                – Neil Galiaskarov
                Jun 10 at 9:51













              up vote
              8
              down vote










              up vote
              8
              down vote









              You can use an inner query:



              var Company = Parse.Object.extend("Company");
              var mainQuery = Parse.Query(Company);

              var UserObject = Parse.Object.extend("User");
              var innerUserQuery = new Parse.Query(UserObject);
              innerBankQuery.equalTo("name", "ABC");
              mainQuery.matchesQuery("bank", innerBankQuery);

              var ansCollection = mainQuery.collection();
              ansCollection.fetch({
              success: function(results) {
              // Do whatever ...
              }
              });





              share|improve this answer












              You can use an inner query:



              var Company = Parse.Object.extend("Company");
              var mainQuery = Parse.Query(Company);

              var UserObject = Parse.Object.extend("User");
              var innerUserQuery = new Parse.Query(UserObject);
              innerBankQuery.equalTo("name", "ABC");
              mainQuery.matchesQuery("bank", innerBankQuery);

              var ansCollection = mainQuery.collection();
              ansCollection.fetch({
              success: function(results) {
              // Do whatever ...
              }
              });






              share|improve this answer












              share|improve this answer



              share|improve this answer










              answered Feb 10 '15 at 4:09









              akarpovsky

              17617




              17617












              • What is innerBankQuery in your example?
                – Neil Galiaskarov
                Jun 10 at 9:51


















              • What is innerBankQuery in your example?
                – Neil Galiaskarov
                Jun 10 at 9:51
















              What is innerBankQuery in your example?
              – Neil Galiaskarov
              Jun 10 at 9:51




              What is innerBankQuery in your example?
              – Neil Galiaskarov
              Jun 10 at 9:51










              up vote
              2
              down vote













              I should say the query will be...



              const userQuery = Parse.Query('_User');

              userQuery.equalTo('name', 'ABC');

              userQuery.find().then((user) => {

              const companyQuery = Parse.Query('Company');

              companyQuery.equalTo('user', {
              __type: 'Pointer',
              className: '_User',
              objectId: user.id
              });

              companyQuery.find().then((company) => {
              console.log(company);
              });
              });





              share|improve this answer

























                up vote
                2
                down vote













                I should say the query will be...



                const userQuery = Parse.Query('_User');

                userQuery.equalTo('name', 'ABC');

                userQuery.find().then((user) => {

                const companyQuery = Parse.Query('Company');

                companyQuery.equalTo('user', {
                __type: 'Pointer',
                className: '_User',
                objectId: user.id
                });

                companyQuery.find().then((company) => {
                console.log(company);
                });
                });





                share|improve this answer























                  up vote
                  2
                  down vote










                  up vote
                  2
                  down vote









                  I should say the query will be...



                  const userQuery = Parse.Query('_User');

                  userQuery.equalTo('name', 'ABC');

                  userQuery.find().then((user) => {

                  const companyQuery = Parse.Query('Company');

                  companyQuery.equalTo('user', {
                  __type: 'Pointer',
                  className: '_User',
                  objectId: user.id
                  });

                  companyQuery.find().then((company) => {
                  console.log(company);
                  });
                  });





                  share|improve this answer












                  I should say the query will be...



                  const userQuery = Parse.Query('_User');

                  userQuery.equalTo('name', 'ABC');

                  userQuery.find().then((user) => {

                  const companyQuery = Parse.Query('Company');

                  companyQuery.equalTo('user', {
                  __type: 'Pointer',
                  className: '_User',
                  objectId: user.id
                  });

                  companyQuery.find().then((company) => {
                  console.log(company);
                  });
                  });






                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Feb 22 '17 at 16:51









                  locropulenton

                  1,68111438




                  1,68111438






















                      up vote
                      0
                      down vote













                      Assuming Your Company collection has a field called User and User collection has a name field, then you can search for Company with user name through
                      companyQuery.equalTo("User.name");



                      This works in Parse 2.1.0






                      share|improve this answer



























                        up vote
                        0
                        down vote













                        Assuming Your Company collection has a field called User and User collection has a name field, then you can search for Company with user name through
                        companyQuery.equalTo("User.name");



                        This works in Parse 2.1.0






                        share|improve this answer

























                          up vote
                          0
                          down vote










                          up vote
                          0
                          down vote









                          Assuming Your Company collection has a field called User and User collection has a name field, then you can search for Company with user name through
                          companyQuery.equalTo("User.name");



                          This works in Parse 2.1.0






                          share|improve this answer














                          Assuming Your Company collection has a field called User and User collection has a name field, then you can search for Company with user name through
                          companyQuery.equalTo("User.name");



                          This works in Parse 2.1.0







                          share|improve this answer














                          share|improve this answer



                          share|improve this answer








                          edited Nov 11 at 7:46









                          Tân Nguyễn

                          1




                          1










                          answered Nov 11 at 7:10









                          Chris Li

                          11




                          11






























                               

                              draft saved


                              draft discarded



















































                               


                              draft saved


                              draft discarded














                              StackExchange.ready(
                              function () {
                              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f26923172%2fquery-on-pointer-in-parse-com-objects-in-javascript%23new-answer', 'question_page');
                              }
                              );

                              Post as a guest















                              Required, but never shown





















































                              Required, but never shown














                              Required, but never shown












                              Required, but never shown







                              Required, but never shown

































                              Required, but never shown














                              Required, but never shown












                              Required, but never shown







                              Required, but never shown







                              Popular posts from this blog

                              List item for chat from Array inside array React Native

                              Thiostrepton

                              Caerphilly