Skip to content

.includeObject in queryBuilder doesn't seem to be including object (not just in appearance due to toString method)? #644

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
perilousGourd opened this issue Jun 12, 2021 · 5 comments

Comments

@perilousGourd
Copy link

I can see that issues like this have been opened several times, with includeObject being found to ultimately work properly in each case. I've not been able to resolve this issue using the existing answers.

I checked in debugger if object is included in results list, as suggested in #420: It seems to not be. Results list is of length 1, containing only Note object. Note object has a field with key 'question' and value ParseObject. The _objectData map of this ParseObject contains two entries, one {'classname', 'Question'} and one {'objectId', 'tjRPWAnCqf'}.

Calling get on containing object resolved #211. As far as I understand, I've done this in the question getter of Note class?

Is something wrong with my parsing of Question object via clone() in Note class question getter?

Note and Question objects created via:

Question question = Question()
  ..content = 'Example question';

Note note = Note()..question = question;
note.save();

Checking in database, note and question exist in form expected.

Fetching attempted via:

QueryBuilder queryBuilder = QueryBuilder<Note>(Note())
  ..whereEqualTo('objectId', '23irEkFVlN')
  ..includeObject(['Question']);

ParseResponse response = await queryBuilder.query();

Note note = response.results![0] as Note;

print('note = ' + note.toString());
print('question = ' + note.question.toString());
print('question.objectId = ' + note.question.objectId.toString());
print('question.content = ' + note.question.content.toString());

output of above print statements:

note =
{"className":"Note","objectId":"23irEkFVlN","createdAt":"2021-06-12T05:18:02.923Z","updatedAt":"2021-06-12T05:18:0
2.923Z","question":{"__type":"Pointer","className":"Question","objectId":"tjRPWAnCqf"}}
questionParseObject = {className: Question, objectId: tjRPWAnCqf}
question = {"className":"Question","objectId":"tjRPWAnCqf"}
questionParseObject = {className: Question, objectId: tjRPWAnCqf}
question.objectId = tjRPWAnCqf
questionParseObject = {className: Question, objectId: tjRPWAnCqf}
question.content = null

I would expect question.content to not return null if question object was included, given my implementation of Note's question getter?

(questionParseObject printed^ due to print statements in the Note class question getter.)

Note and Question classes:
class Note extends ParseObject implements ParseCloneable {
  Note() : super('Note');

  set question(Question question) => set<Question>('question', question);

  Question get question {
    ParseObject questionParseObject = get<ParseObject>('question')!;
    print('questionParseObject = ' + questionParseObject.toJson().toString());
    Question question = Question.clone().fromJson(questionParseObject.toJson());
    return question;
  }


  Note.clone() : this();

  @override
  clone(Map<String, dynamic> map) {
    return Note.clone()..fromJson(map);
  }

class Question extends ParseObject implements ParseCloneable {
  Question() : super('Question');

  set content(String content) => set<String>('content', content);
  String get content => get<String>('content')!;

  Question.clone() : this();

  @override
  clone(Map<String, dynamic> map) {
    return Question.clone()..fromJson(map);
  }
}

Thank you in advance to anyone who notices and lets me know of mistakes in this implementation.

@RodrigoSMarques
Copy link
Contributor

The toString method doesn't show the include objects,

it's just visual. Data has been returned, it's just visual.
You can see these issues here:

#615
#420 (comment)
#420 (comment)

@perilousGourd
Copy link
Author

If data had been returned, wouldn't it show up when I try to access it, e.g. like in this line
print('question.content = ' + note.question.content.toString());
where question was the object that was included and supposedly returned and content is one of its non-null fields?

When I inspect the object in the debugger, as suggested in the #420 comments you linked, I see this:

Results list [in ParseResponse response] is of length 1, containing only Note object. Note object has a field with key 'question' and value ParseObject. The _objectData map of 'question' contains two entries, one {'classname', 'Question'} and one {'objectId', 'tjRPWAnCqf'}.

No other data besides that^ appears in the question ParseObject.

A screenshot:

debug

@RodrigoSMarques
Copy link
Contributor

Your includeObject failed.

You must put the name of the field you want to include and not the name of the class

QueryBuilder queryBuilder = QueryBuilder<Note>(Note())
  ..whereEqualTo('objectId', '23irEkFVlN')
  ..includeObject(['question']);

@perilousGourd
Copy link
Author

Goodness me! No idea how I didn't notice from the examples I was referencing that I was misusing that. I think maybe the variable name 'objectTypes' confused me in the includeObject(List<String> objectTypes) method and resulting prompt while typing, making me think of types/classes rather than fields.

Working for me now perfectly. Thank you very much!

@tehsunnliu
Copy link

tehsunnliu commented Aug 23, 2022

Hi, I'm facing the same problem while using complex queries. I've also made sure that I'm using the field name and not the class name, also I checked the CLP and ACL still not getting the values.

image

Please help thank you.

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

3 participants