ParseReact icon indicating copy to clipboard operation
ParseReact copied to clipboard

equalTo filters for join tables with pointers, on an observed query, return no results

Open jsierles opened this issue 10 years ago • 13 comments
trafficstars

equalTo works as expected when testing outside of React Native in a nodejs script.

However, when observing the same query in RN, no results are returned.

  observe(props, state) {
    query = new Parse.Query('PracticeSessionResource');
    query.equalTo("practice_session", props.practice_session);
    query.include("practice_resource");
    query.include("practice_session");

    return ({
      session_resources: query
    });
  },

jsierles avatar Apr 20 '15 21:04 jsierles

The error provided by Parse is: "pointer field practice_session needs a pointer value"

Despite the fact that I'm passing in an object supplied from the include filter on a previous query.

jsierles avatar Apr 20 '15 21:04 jsierles

Do you need to do a find(); on the query?

  return ({
      session_resources: (query.find())
   });

agnosticdev avatar Apr 20 '15 21:04 agnosticdev

According to the docs, the observed queries should not be fetched prematurely.

jsierles avatar Apr 20 '15 21:04 jsierles

The issue also happens if I test with find() separately, though. The problem seems to be related to the object passed in to equalTo. This doesn't work either, though:

query.equalTo("practice_session", {
      __type: "Pointer",
      className: "_PracticeSession",
      objectId: this.props.practice_session.objectId
    });

jsierles avatar Apr 20 '15 21:04 jsierles

Sorry - the above code in fact does work, I mistyped the className. So this is a workaround, but it would be nice to be able to use the cloned objects returned by the observer to query a pointer field.

jsierles avatar Apr 20 '15 21:04 jsierles

I'll think of the best way to handle this without patching too much of Parse.Query under the hood. In the meantime, you can actually achieve the same behavior above with minimal boilerplate:

q.equalTo('practice_session', Parse.Object('_PracticeSession',
  { id: this.props.practice_session.objectId }));

andrewimm avatar Apr 20 '15 21:04 andrewimm

That works for now - thanks!

jsierles avatar Apr 20 '15 21:04 jsierles

@andrewimm - thank you! Your snippet above works great.

agnosticdev avatar Apr 25 '15 22:04 agnosticdev

Thank you for reporting this issue and appreciate your patience. We've notified the core team for an update on this issue. We're looking for a response within the next 30 days or the issue may be closed.

ghost avatar Aug 04 '15 19:08 ghost

Thank the stars for your solution! I was losing my mind.

WilfredGreyling avatar Sep 18 '15 06:09 WilfredGreyling

It worked for me doing it like this (Parse.Object.extend):

var query = new Parse.Query('Inscription');
query.equalTo('jobOffer', Parse.Object.extend('Offer', { id: this.props.params.offerId}));
query.equalTo('user', Parse.Object.extend('User', { id: this.props.params.userId}));

albertolive avatar Oct 23 '15 10:10 albertolive

They have fixed this issue. You can now supply the object directly: newQuery: (new Parse.Query('parseClassName')) .equalTo('myPointerField', myParseObject )

WilfredGreyling avatar Oct 23 '15 11:10 WilfredGreyling

Thank you!

albertolive avatar Oct 23 '15 11:10 albertolive