Can't write non current user objects by PFUser currentuser
Referencing the above article, there's countless (literally loads) of iOS examples of how to create a many-many relationship between ParseUsers, and yet not a single one written in Android, there's zero documentation on it whatsoever.
If someone could explain how to do this, that'd be great thank you.
I've tried:
ParseUser friend = getParseUser(username); // I search for a friend here
ParseUser user = ParseUser.getCurrentUser(); // this is me, I have rights to write to me
try {
ParseRelation<ParseUser> relation = user.getRelation("friends");
relation.add(friend);
// if I use user.save(); I get no error back obviously - but it does nothing
// if I use user.saveEventually() I get a neverending loop of ParseErrors
// claiming I can't save to that object - Yes I'm logged in.
user.saveInBackground(new SaveCallback() {
//I report errors further on, but the rest is unreachable as this fails.
And lots of varients of that same code. I don't want to use pointers (Parse DB thing) I want to use their relational model, but this code comes back saying unable to encode an association with an unsaved ParseObject
Again, there's lots of documentation for iOS AND for getting ParseObjects or yourself (ParseUser.getCurrentUser()) but there's nothing that shows how you get a ParseUser (not yourself) then create a relationship with them and yourself. Nowhere.
Related
I am triying to delete a field of an object in Back4App, but I cannot achieve such a simple operation. By "deleting" I mean set a field that has data to "undefined".
According to the guide, I just have to call myObject.remove("field"). I tryed that (with correct field name), then save the object (I tried all of the saving functions available), but the object is unmodified. There is no error thrown.
I can change the field (with put ("field", otherObject), because it is a pointer field) with no problem. But put("field", JSONObject.NULL) is not working either.
I do not know if this code would work in the original Parse, I am coding this now. The equivalent function in iOS ([myObject removeObjectForKey:#"field"];) in the same database is working nicely...
For what I could gather from your question, the problem is that you're trying to clean a field from a relational object:
"I can change the field (with put ("field", otherObject), because it is
a pointer field)"
On that case, I'm not really sure if using simple object deletion would work. I'd suggest you to take a look at Parse's documentation on Relational Data in order to understand how you should remove that field.
Long story short, I'm not sure if the idea of cleaning the field that you wish will work, but what can be done when you have a relation like this:
ParseUser user = ParseUser.getCurrentUser();
ParseRelation<ParseObject> relation = user.getRelation("field");
relation.add(MyObject);
user.saveInBackground();
Is to simply remove the relation like this:
relation.remove(MyObject);
As you can check in the link above.
I am new to couchbase and I am trying to implement couchbase lite in one of my Android applications. What i am struggling with in particular is the concept of views and the rules for the map function as stated in the docs.
In the database the app stores documents with various doc types. In one query i need to get the entire document by document type ("payments")
and by value of an attribute of the document (doc["approved"] = true)
Hence I would create a view like so:
com.couchbase.lite.View view = database.getView("payments");
if (view.getMap() == null) {
Mapper map = new Mapper() {
#Override
public void map(Map<String, Object> doc, Emitter emitter) {
if (doc.get("type").equals("payments") && doc.get("approved") == true) {
emitter.emit(doc.get("name"), doc);
}
}
};
view.setMap(map, "1");
}
Note that the doc["approved"] value can be updated over time. In one of the rules about map functions in the docs it says:
It must be a "pure" function: ... That means any time it's called with the
same input, it must produce exactly the same output.
Would the implementation of the map function as show above violate that rule?
In the docs it further says :
In particular, avoid these common mistakes: ... Don't make any assumptions
about when the map function is called. That's an implementation detail
of the indexer. (For example, it's not called every time a document
changes.).
Does that mean when the approved status of one of the documents is updated from false to true that the following query not nessesarily contains the updated document? If so what would I need to do to achieve this? I am quite uncertain about what rule that exacly means? Could anyone try to open my eyes please?
What "pure" means is that you cannot use outside state in your map function. All your determinations must be based solely on the parameters that were passed into it. Your map function does not violate this.
I think the missing piece in your understanding is the difference between storage and indexing. You can store revisions of a document to the database, right? That in and of itself will not cause the view's index to be updated. That's what the documentation means by "not called every time a document changes." The index will be updated by default when the next query is run, so the newest state of the document will be output. It could realistically have been changed many times since the last query was run.
For a new project I was running some tests. For now I have a function in which I am trying to save an object to the parse.com framework and all went well untill I added a user pointer object. The pointer line seems to block my code when I use the current user's objectId as a value for it. Using a random word of the user's email adres however does work. I added my code below.
// Create a data object and store it online.
public void createDataObject(){
ParseObject object = new ParseObject("TestData");
object.put("action", "trial");
object.put("value", "succes?");
object.put("name", ParseUser.getCurrentUser().getUsername());
String pointer = ParseUser.getCurrentUser().getObjectId();
Log.i(TAG, pointer);
object.put("pointer", ParseObject.createWithoutData("_User", pointer));
object.saveEventually();
}
I hope anyone can help me figure it out, help is greatly appreciated!
Update: The problem is not my pointer command but it's the fact I use saveEventually(); If I use saveInBackground it just works but I want to use saveEventually because of possible lost network connection. Does anyone have a clue what could be the problem?
Update 2: Finally decided to delete the app and the installationId of the Parse data browser. Upon reinstalling the app everything started working like it should. I probably had a bad piece of code that got stuck with my installation Id. I hope others with the same problem reach this post fast and don't spend several days searching for an answer!
Update 3: There was a certain function that tried to find a user based on a pointer with the app user's object ID which made the app crash once and than totally unusable. I marked the first answer as the correct answer since it solved my original question but just fyi.. there was more going on than I expected at first.
Just try this:
public void createDataObject(){
ParseObject object = new ParseObject("TestData");
object.put("action", "trial");
object.put("value", "succes?");
object.put("name", ParseUser.getCurrentUser().getUsername());
object.put("pointer", ParseUser.getCurrentUser());
object.saveEventually();
}
No need to get the object ID to set the current User.
Edit:
You can also refer https://stackoverflow.com/a/28403968/2571060 to set pointer
I had a similar issue with the iOS SDK. Are you using 'automatic user creation' ? Cause in that case, ParseUser.getCurrentUser() returns a User object whose objectId is null. According the documentation, it is null until the user or any object related to it is saved. But in my experience, it is not the case, I had to save the user first or I would get an error like 'User can only be created during signUp' or something like this.
Here is the deal. One of my activities requires for ID and password input to login. How can i check if login was successful ( the main idea is to check if such account exists, but I do NOT have access to database to check for it. So I need an alternative : if I'm able to login - thats OK, if not - drop alertDialog with message and let user try to input right data). How can i do that with Jsoup ?
Here is the piece of code I'm using in AsyncTaskLoader to do login and retrieve some data :
Connection.Response response = Jsoup.connect(URL)
.data("id", paramID, "password", paramPassword)
.timeout(10000)
.method(Connection.Method.POST)
.execute();
String cookie = response.cookie("JSESSIONID");
Document document = Jsoup.connect(targetURL)
.cookie("JSESSIONID", cookie)
.get();
Any ideas how to do that ? Thanks :)
Your question as I understand it: you want to test to see if the user name and password you have used is valid.
You need to know two things:
What the subsequent page looks like in event of a successful login.
What the subsequent page looks like in event of an unsuccessful login.
So, use this:
Document document = Jsoup.connect(targetURL)
.cookie("JSESSIONID", cookie)
.get();
This is going to take some investigation on your part. You need to inspect the two different pages and find a single element that exists in one or both of them that will allow you to distinguish between a successful login and a failed login.
For example, if you're lucky, you might be able to compare the titles of the document like this:
if (document.title().contains("Login Successful or whatever")){
// DO SOMETHING
} else if (document.title().contains("Login Unsuccessful or something else")){
// DO SOMETHING ELSE
};
Like I said, that's if you're lucky. Otherwise you're going to have to go investigate and examine the respective html pages and figure out a convenient element to use to test the two pages for.
Hope that helps.
I am having a weird issue here.
The class Points I want to save data into, has two columns race and challenge which are relations to other classes with the same name.
I have asked this question on Parse.com forums as well
On the client side on Android, if I add the relation via pointsObject.put("race", raceObject), it throws an error saying that the type of "race" is Relation and I am providing a *Pointer
The iOS Counterpart of the app I am working on is completely able to save relations nicely - Happily Coded about 2 hours ago
When I use ParseRelation to add a one-to-many relationship, it takes only the first class as target class.
This code should explain:
ParseRelation<ParseObject> initiatorChallengeRelation = initiatorPoints.getRelation("Points");
initiatorChallengeRelation.add(challenge);
initiatorPoints.put("challenge", initiatorChallengeRelation);
ParseRelation<ParseObject> initiatorRaceRelation = initiatorPoints.getRelation("Points");
initiatorRaceRelation.add(race);
initiatorPoints.put("race", initiatorRaceRelation);
The first block of code sets the target class for the relation as "Challenge".
The second block tries to set the target class of the new ParseRelation object to "Race", but initiatorRaceRelation.add(race) is where it fails and throws an error : "IllegalArgumentException: Related object object must be of class Challenge, but Race was passed in."
I used Eclipse Debugger to check the data in the both Relation objects and found the thing about target classes being the same
Any help on where I might be going wrong?
I have been dealing with this issue since more than 12 hours and its really become a roadblock for me.
Any help would be deeply appreciated
Is Points a relation? From what you have mentioned, it seems so.
Assuming that initiatorPoints is a Points Object, you should get the challenge relation using
ParseRelation<ParseObject> initiatorChallengeRelation = initiatorPoints.getRelation("challenge"); //for challenge
then
initiatorChallengeRelation.add(challenge);
Similarly, for race
ParseRelation<ParseObject> initiatorRaceRelation = initiatorPoints.getRelation("race"); //for race
initiatorRaceRelation.add(race);
I think you need not even use initiatorPoints.put("challenge", initiatorChallengeRelation);
Once, you say
initiatorPoints.saveInBackground(callback), Parse updates the changes in the object by itself.
But do not forget to save the object once you have added the relation data. Hope this helps!