Why does the query not return results after I switch the class it queries?

Dano007

Parse.com and JavaScript SDK.

UPDATED from answer below

function friendFeed() {
    friendName = $('#friendsearch').val();
    console.log(friendName);
    var query = new Parse.Query(myBadges);

new Parse.Query("myBadges").matchesQuery("username", new Parse.Query("_User").equalTo("username", friendName))

    query.find({

Right this makes no sense! the below code works as expected below and returns a user when I use the _User class in the variable "myBadges" BUT

if I swap this for the class myBadges which contains a pointer to _User no results are returned

I don't understand why that would be happening?

var friendName;
var currentUser = Parse.User.current();
var myBadges = Parse.Object.extend("myBadges");


// Captures the input from the user and checks if the name already exists within the Db.
function findFriend() {
    friendName = $('#friendsearch').val();
    console.log(friendName);
    var query = new Parse.Query(myBadges);
    //query.include("BadgeName");
    //ery.include('mtBadgesPOINTER');
    query.equalTo("username", friendName); // find users that match

    query.find({
        success: function (friendMatches) {

            $('#imgs').empty();
            $('#no_user').hide();
            // This section is always run, no matter the outcome. Depending on the input depends on which result is shown
            console.log(friendMatches);
            if (friendMatches.length === 0)
                $('#no_user').show();
            console.log('NO MATCH FOUND!!!')

        },
        error: function (error) {
            alert('Opps we have a problem' + error.message);
        }
    });

}

////////////////////////////////////////////////////////////

$('#find_button').click(function (e) {
    findFriend();
});

< /script>
<div id="imgs"></div >
    < img style = "display:none"
src = "/img/no-user.png"
id = "no_user"
alt = "No user found" >

enter image description here

ryanjduffy

That's how it's supposed to work. Because you've established a pointer to User from myBadges you need to query using a pointer as well. Pass the string value of the username doesn't work because the string doesn't equal the pointer.

If you're using the username to look up badges, you'd need a query along this line:

new Parse.Query("myBadges").matchesQuery("username", new Parse.Query("_User").equalTo("username", friendName))

Which uses compound queries to find users matching the given username and then myBadges where the user equals a result from the first query.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Why does this query return no results?

From Dev

Why does this query return no results?

From Dev

Why does not this DL query return expected results?

From Dev

<> or NOT IN, and why does query return wrong results

From Dev

Why does this javascript function return two different results for the same query?

From Dev

Why does this Linq Query Return Different Results than SQL Equivalent?

From Dev

Does anyone know why I am not getting any results with this query?

From Dev

Why does this Query return NULL?

From Dev

Why won't this query return results that are 0?

From Dev

Elasticsearch OR filtered query does not return results

From Dev

Simple SPARQL query does not return any results

From Dev

Why do these two linq queries return different numbers of results?

From Dev

Why do these 2 MySQL queries return different results

From Dev

Why does a PostgreSQL SELECT query return different results when a schema name is specified?

From Dev

My query to retrieve events between 2 search dates does not return any results, why?

From Dev

Why beautiful soup does not return the results in order?

From Dev

Why does strpos return different results?

From Dev

Why does Q object return duplicated results?

From Dev

Why does my sqlite selection return no results?

From Dev

Why does the regex in find not return any results?

From Dev

Why does DATEDIF return different results for these values?

From Dev

why this stored does'nt return results

From Dev

MySQL: How do I efficiently reuse the results of a query in other queries?

From Dev

Why does this range query returns empty results?

From Dev

After I switch default SSH ports, why does NMAP display port service as "down"

From Dev

Why do I get more results for querying all instances of a subclass than for a query on the "parent" class?

From Dev

Why does Microsoft Azure (or Swift in general) fail to update a variable to return after a table query?

From Dev

Why does this query give different results depending on how I arrange my DateTime arithmetic?

From Dev

Why exactly does this Lucene query return no hits?

Related Related

  1. 1

    Why does this query return no results?

  2. 2

    Why does this query return no results?

  3. 3

    Why does not this DL query return expected results?

  4. 4

    <> or NOT IN, and why does query return wrong results

  5. 5

    Why does this javascript function return two different results for the same query?

  6. 6

    Why does this Linq Query Return Different Results than SQL Equivalent?

  7. 7

    Does anyone know why I am not getting any results with this query?

  8. 8

    Why does this Query return NULL?

  9. 9

    Why won't this query return results that are 0?

  10. 10

    Elasticsearch OR filtered query does not return results

  11. 11

    Simple SPARQL query does not return any results

  12. 12

    Why do these two linq queries return different numbers of results?

  13. 13

    Why do these 2 MySQL queries return different results

  14. 14

    Why does a PostgreSQL SELECT query return different results when a schema name is specified?

  15. 15

    My query to retrieve events between 2 search dates does not return any results, why?

  16. 16

    Why beautiful soup does not return the results in order?

  17. 17

    Why does strpos return different results?

  18. 18

    Why does Q object return duplicated results?

  19. 19

    Why does my sqlite selection return no results?

  20. 20

    Why does the regex in find not return any results?

  21. 21

    Why does DATEDIF return different results for these values?

  22. 22

    why this stored does'nt return results

  23. 23

    MySQL: How do I efficiently reuse the results of a query in other queries?

  24. 24

    Why does this range query returns empty results?

  25. 25

    After I switch default SSH ports, why does NMAP display port service as "down"

  26. 26

    Why do I get more results for querying all instances of a subclass than for a query on the "parent" class?

  27. 27

    Why does Microsoft Azure (or Swift in general) fail to update a variable to return after a table query?

  28. 28

    Why does this query give different results depending on how I arrange my DateTime arithmetic?

  29. 29

    Why exactly does this Lucene query return no hits?

HotTag

Archive