Skip to content

ParseQuery with ParseRelation #44

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
ghost opened this issue Apr 21, 2017 · 6 comments
Closed

ParseQuery with ParseRelation #44

ghost opened this issue Apr 21, 2017 · 6 comments

Comments

@ghost
Copy link

ghost commented Apr 21, 2017

Hey,

I wanted to do a live query operation with a ParseRelation.

Here is my code:
ParseRelation<ParseObject> relation = channel.getRelation("messages");
ParseQuery<ParseObject> query = relation.getQuery();
query.whereEqualTo("messageText", "test");

With this code I don´t get any response from server. If I do a query
without a relation, it works well.

Is ParseRelation not possible in association with LiveQuery?

Thanks in advance.

@jhansche
Copy link
Contributor

What's the actual structure of your data object(s)? And what's the JSON query that is being sent in the subscribe call? And does it work if you use query.findInBackground(new FindCallback ...);?

query.findInBackground() will try to locate the object(s) that match that query. If you get no data from that query, then you will also get no response in the LiveQuery.

@ghost
Copy link
Author

ghost commented Apr 27, 2017

I did execute the query with query.findInBackground(new FindCallback ...); and I got all objects, which are exists in the relation.

This is the data structure:
Class Channel:
This object contains a ParseRelation to class "Message".
The column is named "messages".

Class Message:
A message has a "messageText" and an owner (ParseUser pointer).

My subscribtion: subscriptionHandling = liveQueryClient.subscribe(query);

So with FindInBackground I get all objects in the relation, but with live query it is not working.
Did you tried a subscription to a ParseRelation?

@jhansche
Copy link
Contributor

No, I haven't - just wanted to address the first part before looking, because if the query itself doesn't work, the LiveQuery can never possibly work :)

But according to parse-community/parse-server#2946, what you're asking for is not supported.

I have personally tested and used ParsePointer LiveQueries, and that does work. But apparently ParseRelation does not work on the server side yet.

One option: you may be able to change your objects so that instead of:

class Channel {
  ParseRelation<Message> getMessages() { return getRelation("messages"); }
}
class Message {}

you can change it so the Message has a pointer to the Channel instead:

class Channel { ... }
class Message {
  Channel getChannel() { return (Channel) getParseObject("channel"); }
}

and then your query and LiveQuery can use a Pointer reference, instead of a Relation reference:

Channel myChannelObj = ...;
ParseQuery<Message> messagesQuery = ParseQuery.getQuery(Message.class).whereEqualTo("channel", myChannelObj);
// messagesQuery.find() should still work same as before
liveQuery.subscribe(messagesQuery); // then should work also.

I know for certain that ParsePointer queries like this work, because my project does exactly this (and I made the commit that allows it to work correctly).

@jhansche
Copy link
Contributor

Do you have the JSON string that is being sent for the ParseRelation query on subscribe? That might help track it down if the above isn't a solution.

But given that the parse server issue is still open, saying this is not supported, the above alternative may be your only option.

@ghost
Copy link
Author

ghost commented Apr 28, 2017

After I saw, that live query with ParseRelation is not working, I used the solution which you posted.
With this data model it works really well.

Thank you for your quick response. :)

@ghost ghost closed this as completed Apr 28, 2017
@Edijae
Copy link

Edijae commented Sep 28, 2019

Is livequery on parserelation not yet supported?

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants