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.
javascript parse.com cloud-code
add a comment |
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.
javascript parse.com cloud-code
add a comment |
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.
javascript parse.com cloud-code
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
javascript parse.com cloud-code
asked Nov 14 '14 at 4:56
Yatin Mehandiratta
632620
632620
add a comment |
add a comment |
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() {
}
});
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
add a comment |
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 ...
}
});
What isinnerBankQueryin your example?
– Neil Galiaskarov
Jun 10 at 9:51
add a comment |
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);
});
});
add a comment |
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
add a comment |
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() {
}
});
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
add a comment |
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() {
}
});
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
add a comment |
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() {
}
});
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() {
}
});
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
add a comment |
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
add a comment |
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 ...
}
});
What isinnerBankQueryin your example?
– Neil Galiaskarov
Jun 10 at 9:51
add a comment |
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 ...
}
});
What isinnerBankQueryin your example?
– Neil Galiaskarov
Jun 10 at 9:51
add a comment |
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 ...
}
});
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 ...
}
});
answered Feb 10 '15 at 4:09
akarpovsky
17617
17617
What isinnerBankQueryin your example?
– Neil Galiaskarov
Jun 10 at 9:51
add a comment |
What isinnerBankQueryin 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
add a comment |
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);
});
});
add a comment |
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);
});
});
add a comment |
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);
});
});
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);
});
});
answered Feb 22 '17 at 16:51
locropulenton
1,68111438
1,68111438
add a comment |
add a comment |
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
add a comment |
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
add a comment |
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
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
edited Nov 11 at 7:46
Tân Nguyễn
1
1
answered Nov 11 at 7:10
Chris Li
11
11
add a comment |
add a comment |
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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