it should be possible
not sure if this helps: https://stackoverflow.com/questions/26923172/query-on-pointer-in-parse-com-objects-in-javascript
it should be possible
not sure if this helps: https://stackoverflow.com/questions/26923172/query-on-pointer-in-parse-com-objects-in-javascript
useEffect(async () => {
const Comments = Moralis.Object.extend("Comments");
const query = await new Moralis.Query(Comments);
const object = await query.find({
function(results) {
var userPointer = {
__type: "Pointer",
title: results.resultId
}
query.equalTo("post", userPointer);
query.find({
success: function(results) {
console.log(results)
},
error: function() {
console.log("Error");
}
})
},
});
so would this find the title of the post query? but it finds me all the comments
it looks like you run query.find once, where it will find all the comments
what you want to do after that?
want to search inside the comments for the pointer āpostā and inside the pointer post, find the title that it matches with the current slug which is the title of the post
I think that you can include that post object in the original query, with query.select and query.include so that you can access it directly
something like in this post: [SOLVED] Receiving empty array of results when trying to fetch data from the user table
okay so like this i get all the posts:
useEffect(async () => {
const Comments = Moralis.Object.extend("Comments");
const query = await new Moralis.Query(Comments);
query.include("post");
query.equalTo("title", resultId)
const middleresult = await query.find();
const results = JSON.stringify(middleresult, null, 2)
const finalResult = JSON.parse(results)
console.log(finalResult)
for (let i = 0; i < middleresult.length; i++) {
// This does not require a network access.
const post = middleresult[i].get("post");
console.log(post)
}
}, )
But how would you make it so that it only renders the ones that matches the title of the post? Iāve tried with query.equalTo("title", resultId)
where resultId is the name of the post. But this doesnāt get me the results as it just renders an empty array.
I donāt understand what is resultId, and the title is from Comments table accessible directly?
you may have to use something like query.equalTo("post.title", title_post)
okay iāve tried this and it works up until the query, because the query doesnāt get stringified. What can that be due to? When I console log the finalresult it just appears an empty array. But when I console log the query, it appears the values
useEffect(async () => {
const Comments = Moralis.Object.extend("Comments");
const query = await new Moralis.Query(Comments);
query.equalTo("post.title", resultId);
console.log(query)
const middleresult = await query.find();
const results = JSON.stringify(middleresult, null, 2)
const finalResult = JSON.parse(results)
console.log(finalResult)
}, [data])
you can try to comment this line to see if you get all the comments, maybe that equalTo doesnāt work yet (it could be from the value of resultId, or maybe is not accessible with post.title)
Iām not sure what you expect to get with this console.log, the query is not executed yet.
you can add directly after this line a console.log(JSON.stringify(middleresult))
without the need for the next two lines
I do get the values in
query.equalTo("post.title", resultId);
but later on, when I console log the stringify values I no longer get the values. I get an empty array
on what values are you referring?
the comments that correspond with the title of post.title
I think that it is only the query information, without any data yet.
so āpost.titleā doesnāt work right?
or what you have in that resultId
could not match anything
you can try without that line to see if you get all the results, add an query.include(āpostā) to see how the data looks like and after that to try again by adding that query.equalTo
yes, I do get the vallues without that line, but resultId in theory is the title of the post, you know?
I know that it should be the title of the post, but I donāt know exactly what you had in that variable name
if you get the values without that line, then you have to see what is not working well with that query.equalTo line
what i donāt understand is why this finding me the comments query but it is not finding it with the post pointer:
so the console log outputs me all the query, but without the posts
useEffect(async () => {
const Comments = Moralis.Object.extend("Comments");
const query = await new Moralis.Query(Comments);
const middleresult = await query.find();
console.log(JSON.stringify(middleresult))
}, [data])
but you can still see a pointer for posts here, right?
I think that you have to use query.include and/or query.select to include the post data that normally is a pointer