Skip to content

whereEqualTo Pointer returns no results #57

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
Saifallak opened this issue Jan 27, 2019 · 13 comments
Closed

whereEqualTo Pointer returns no results #57

Saifallak opened this issue Jan 27, 2019 · 13 comments

Comments

@Saifallak
Copy link
Contributor

Saifallak commented Jan 27, 2019

DB :
https://i.ibb.co/RQsn3CG/Untitled.jpg

when i try to query with

var query = QueryBuilder<SubscriptionParse>(SubscriptionParse())
  ..whereEqualTo('operator', 'E5um4KqOMD');
var response = await query.query();

i get no result found ,, shouldn't i get 5 results ?

SubscriptionParse Class :

import 'dart:core';

import 'package:AppName/screens/home/tele-services.dart';
import 'package:flutter/material.dart';
import 'package:parse_server_sdk/parse.dart';

class SubscriptionParse extends ParseObject implements ParseCloneable {
  SubscriptionParse() : super(_keyTableName);
  SubscriptionParse.clone() : this();

  @override
  clone(Map map) => SubscriptionParse.clone()..fromJson(map);

  static const String _keyTableName = 'Subscription';
  static const String _keyObjectID = 'objectId';
  static const String _keyOperator = 'operator';
  static const String _keyName = 'name';
  static const String _keyDescription = 'description';
  static const String _keyLogo = 'logo';

  String get name => get<String>(_keyName);
  set name(String name) => set<String>(_keyName, name);

  String get description => get<String>(_keyDescription);
  set description(String name) => set<String>(_keyDescription, description);

  String get logo => get<String>(_keyLogo);
  set logo(String logo) => set<String>(_keyLogo, logo);

  String get objectId => get<String>(_keyObjectID);
  set objectId(String objectId) => set<String>(_keyObjectID, objectId);

  String get operatorID => get(_keyOperator).toString();
  set operatorID(String operator) => set<String>(_keyOperator, operator);
}
@phillwiggins
Copy link
Member

The issue is that your trying to search for a string, but the operator object is not a string, it's a pointer.

Create an instance of your operator object with the ID that your trying to search. Then when querying call

var query = QueryBuilder<SubscriptionParse>(SubscriptionParse())
  ..whereEqualTo('operator', instanceOfOperatorObject.toPointer());

@Saifallak
Copy link
Contributor Author

Sorry but how exactly get instance of Operator Object ?

@phillwiggins
Copy link
Member

phillwiggins commented Jan 27, 2019 via email

@Saifallak
Copy link
Contributor Author

Saifallak commented Jan 27, 2019

    var y = ParseObject("Operator")..set("objectId", "E5um4KqOMD");
// {"className":"Operator","objectId":"E5um4KqOMD"}

    var query = QueryBuilder<SubscriptionParse>(SubscriptionParse())
      ..whereEqualTo('operator', y.toPointer());
// as pointer => {'__type': 'Pointer', className: Operator, objectId: E5um4KqOMD}

still getting zero results ,, i'm miss understanding ?

@phillwiggins
Copy link
Member

phillwiggins commented Jan 27, 2019 via email

@phillwiggins
Copy link
Member

Might have fixed this in the recent release. Potentially was an encoding issue. I have the updated version on our develop branch if you wish to test again.

@Saifallak
Copy link
Contributor Author

Saifallak commented Jan 28, 2019

Okay ,, the encoding changed a bit ,,
now :

     var y = ParseObject("Operator")..set("objectId", "E5um4KqOMD");

// {"className":"Operator","objectId":"E5um4KqOMD"}

    var query = QueryBuilder<SubscriptionParse>(SubscriptionParse())
      ..whereEqualTo('operator', y.toPointer());

// now : {"__type": "Pointer", "className": "Operator", "objectId": "E5um4KqOMD"}
// was : {'__type': 'Pointer', className: Operator, objectId: E5um4KqOMD}

now getting :

I/flutter ( 4128): API Response (Subscription : ParseApiRQ.query) :
I/flutter ( 4128): Status Code: 1
I/flutter ( 4128): Type: No Results
I/flutter ( 4128): Error: null
I/flutter ( 4128): ----
I/flutter ( 4128): AppName: null

@Saifallak
Copy link
Contributor Author

Saifallak commented Jan 28, 2019

tried changing the encoding in parse_encoder.dart
to :

return "{\'__type\': \'Pointer\', \'$keyVarClassName\': \'${object.className}\', \'$keyVarObjectId\': \'${object.objectId}\'}";

instead of

return "{\"__type\": \"Pointer\", \"$keyVarClassName\": \"${object.className}\", \"$keyVarObjectId\": \"${object.objectId}\"}";

changed double Quotes to single Quote
now getting no results to ,, idk if this helps

I/flutter ( 4128): API Response (Subscription : ParseApiRQ.query) :
I/flutter ( 4128): Status Code: 200
I/flutter ( 4128): Reponse: OK
I/flutter ( 4128): ----
I/flutter ( 4128): AppName: Successful request, but no results found

@phillwiggins
Copy link
Member

I'm stumped. I recreated your object, and table setup.

I noticed an issue with encoding again... But that still has not returned any results. I checked my output against the documentation and it just doesn't seem to bring any results back.

@CodeGenie1
Copy link

I've encountered the same issue when trying to query with pointers. I used the parse console to test out some queries and this is what works ok in the console :

where={"owner": {"__type": "Pointer","className":"_User", "objectId": "vKstDRHhfr"}}

Comparing this to what is happening in the parse server sdk, it appears that because the value is being encoded into a string, in ParseQuery @ line 233 it then adds additional quotes around the value

var value = convertValueToCorrectType(columnAndValue.value);

So it ends up as where={"owner": "{"__type": "Pointer","className":"_User", "objectId": "vKstDRHhfr"}"}

I changed the code at line 233 to :
var value;
if (columnAndValue.value is String && columnAndValue.value.contains("__type")) {
value = columnAndValue.value;
} else {
value = convertValueToCorrectType(columnAndValue.value);
}

and this made the query work ok. So I think that is the issue.

Hope that helps, and many thanks for developing the SDK, a great job !

@CodeGenie1
Copy link

Noticed another minor thing, when objects are being returned from queries the className field is being set to "className" instead of the object type. It's being caused when the parse objects are cloned, in ParseObject the className field is always set to 'ClassName' when cloned.

class ParseObject extends ParseBase implements ParseCloneable {
ParseObject.clone(String className) : this**('className'**);

Not sure if this was meant to be this way for some other reason, but if the className is passed through it fixes this.

class ParseObject extends ParseBase implements ParseCloneable {
ParseObject.clone(String className) : this(className);

Only minor things, otherwise it's working really nicely !

@RodrigoSMarques
Copy link
Contributor

@CodeGenie1
It's working. You can test with last release.

     final localUser = await ParseUser.currentUser();
      var queryBuilder = QueryBuilder<ParseObject>(ParseObject('Product'))
        ..whereEqualTo("owner", localUser.toPointer());

@phillwiggins
Copy link
Member

Thanks @RodrigoSMarques.

This was resolved in version 1.0.15.

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

4 participants