Reputation: 11
I have a pointer from the _User
table to a table named StoreData
.
after signing-up a _User, "StoreData" is filled and then a pointer from _User
to StoreData
is created and stored in _User.
Now when the user logs in, a variable stores the object of StoreData
which is named storeData
.
when the user logs in for the first time, storeData.get("city")
returns "NewDelhi". But after that the user has logged out and then logs in again it always returns undefined, Although there has been no change in the database.
Here is my code:
To register a User:
var StoreData = Parse.Object.extend("StoreData");
var storeData = new StoreData();
storeData.set("storeName",storeName);
storeData.set("phoneNumber1",phoneNumber1);
storeData.set("addressLine1",addressLine1);
storeData.set("addressLine2",addressLine2);
storeData.set("city",city);
storeData.set("state",state);
storeData.set("pinCode",pinCode);
storeData.set("location",location);
if(hasAuth>0){
storeData.set("hasAuth",true);
}
else{
storeData.set("hasAuth",false);
}
if(phoneNumber2.length>0){
storeData.set("phoneNumber2",phoneNumber2);
}
if(phoneNumber3.length>0){
storeData.set("phoneNumber3",phoneNumber3);
}
if(email2.length>0){
storeData.set("email2",email2);
}
if(landMark.length>0){
storeData.set("landMark",landMark);
}
storeData.save(null,{
success: function(storeData){
var user = new Parse.User();
user.set("username",email);
user.set("password",password);
user.set("store",storeData);
user.signUp(null, {
success: function(user){
alert("Successfull");
window.open("adminPage.html","_self");
},
error: function(error){
alert("here");
alert(error.message);
}
});
},
error: function(storeData,error){
alert(error.message);
}
);
User is successfully signed up which is evident from the fact that it the following code is working when user logs in:
var currentUser = Parse.User.current();
if(currentUser){
var storeData = currentUser.get("store");
alert(storeData.get("city"));
var city = storeData.get("city");
alert(city);
for the first time, the alert gives the city name but second login onwards it returns undefined.
What am I doing wrong?
Upvotes: 1
Views: 236
Reputation: 119031
In the latter runs the user has its pointer data populated but the object(s) pointed to aren't populated.
There are 2 ways to populate them:
includeKey
on the fetch with the key of the pointerfetch
the pointed to objectFor your user you don't actually make a fetch yourself so you should fetch the pointed to object before you try to use it.
Upvotes: 1