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" >
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.
Comments