Skip to content
New issue

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

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

Already on GitHub? # to your account

Included objects in model #10

Closed
aBuder opened this issue Dec 23, 2018 · 24 comments
Closed

Included objects in model #10

aBuder opened this issue Dec 23, 2018 · 24 comments

Comments

@aBuder
Copy link

aBuder commented Dec 23, 2018

Hi, is there an example available, where I have an Pointer object included in an response?

@phillwiggins
Copy link
Member

phillwiggins commented Dec 23, 2018 via email

@aBuder
Copy link
Author

aBuder commented Dec 23, 2018

Should you need help? Hole long I have to wait for feature?

@phillwiggins
Copy link
Member

phillwiggins commented Dec 23, 2018 via email

@phillwiggins
Copy link
Member

Hey, should be able to work with this now?

@ghost
Copy link

ghost commented Jan 15, 2019

For me, it's actually not working but from the REST API Guide, it seems that it could be easier than doing double queries.

For example, if we have Diet_Plans objects with GameScore pointer, we can retrieve complete GameScore object with one include.

curl -X GET \
  -H "X-Parse-Application-Id: APPLICATION_ID" \
  -H "X-Parse-REST-API-Key: ${REST_API_KEY}" \
  -G \
  --data-urlencode 'include=["gameScore"]' \
https://parseapi.back4app.com/classes/Diet_Plans

Update

Ok after, I saw that include was possible in the SDK but I test it and it doesn't work.

void query() async {
    var queryBuilder = QueryBuilder<DietPlan>(DietPlan());

    queryBuilder.include("gameScore");

    var response = await queryBuilder.query();

    //...
  }

@phillwiggins
Copy link
Member

That's not the correct implementation of it...

include should be added to a query... i.e. queryBuilder.greaterThan(DietPlan.keyFat, 20);

void query() async {
    var response = await QueryBuilder<DietPlan>(DietPlan());
    ..greaterThan(DietPlan.FAT, 20)
    ..include("gameScore")
    .query();
}

Try something like that? I'm not sure if the syntax is correct but the include statement simple tells the api to include the full object, rather than just a pointer reference.

@ghost
Copy link

ghost commented Jan 15, 2019

I tried many times and your syntax isn't correct :/

@phillwiggins
Copy link
Member

phillwiggins commented Jan 15, 2019

Would this work? There was a semi colon added incorrectly. Regardless, build a query that will actually return an object that contains another object.

void query() async {
var response = await QueryBuilder(DietPlan())
..greaterThan(DietPlan.FAT, 20)
..include("gameScore")
..query();
}

@ghost
Copy link

ghost commented Jan 15, 2019

No, there is en error for the line '..include("gameScore")'

The expression here has a type of 'void', and therefore cannot be used.

@phillwiggins
Copy link
Member

This isn't related to the library. Please review the edited comment above. This is Dart syntax issues over library issues.

@ghost
Copy link

ghost commented Jan 16, 2019

I test your code

void query() async {
var response = await QueryBuilder(DietPlan())
..greaterThan(DietPlan.FAT, 20)
..include("gameScore")
..query();
}

It's strange because your response variable is not a response (ParseResponse) but it's a QueryBuilder so I don't know how can I print the list of DietPlan for example. Do you have an idea ?

@phillwiggins
Copy link
Member

Apologies, I'm not in front of a computer most times I am responding to you. Have you tried building the query as per the documentation.. i.e.

void query() async {
     var queryBuilder = await QueryBuilder(DietPlan())
     ..greaterThan(DietPlan.FAT, 20)
     ..include("gameScore");
     var response = await queryBuilder.query();
}

That should work?

@ghost
Copy link

ghost commented Jan 16, 2019

I have a response but the include doesn't work, I don't have the complete gameScore object.

@phillwiggins
Copy link
Member

Does your DietPlan table have a reference to an object called 'gameScore'? Please can you screenshot your Parse Dashboard with the table DietPlan on screen. Thanks

@ghost
Copy link

ghost commented Jan 16, 2019

https://image.noelshack.com/fichiers/2019/03/3/1547631106-capture-d-ecran-2019-01-16-a-10-30-54.png

And the result:

Result: [{"className":"Diet_Plans","objectId":"U4FyTrkpBH","createdAt":"2019-01-11T10:40:08.121Z","updatedAt":"2019-01-16T09:28:51.569Z","Name":"Test1","Fat":666,"gameScore":"{'__type': 'Pointer', className: GameScore, objectId: ebqAUbJrKw}"}, {"className":"Diet_Plans","objectId":"TrcvvdZEiU","createdAt":"2019-01-16T09:20:17.727Z","updatedAt":"2019-01-16T09:30:21.996Z","Fat":30,"Name":"Test2","gameScore":"{'__type': 'Pointer', className: GameScore, objectId: ebqAUbJrKw}"}]

@phillwiggins phillwiggins reopened this Jan 16, 2019
@phillwiggins
Copy link
Member

Confirmed... This does look like a bug. I'll try and add a fix for 1.0.6.

Thanks for letting me know.

@phillwiggins
Copy link
Member

Can we test this again? The code looks identical to other SDK's and should be working? I've added support for query encoding that might potentially work better...

@ghost
Copy link

ghost commented Jan 21, 2019

I test but I doesn't work, I don't have the full object GameScore in my response

My code :

void query() async {
    var queryBuilder = QueryBuilder(DietPlan())
      ..includeObject(["gameScore"]);

    var response = await queryBuilder.query();

    if (response.success && response.result != null) {
      print(
          "Result: ${((response.result as List<dynamic>).first as DietPlan).toString()}");
    } else {
      print("Result: ${response.error.message}");
    }
  }

My console :

Result: {"className":"Diet_Plans","objectId":"U4FyTrkpBH","createdAt":"2019-01-11T10:40:08.121Z","updatedAt":"2019-01-18T15:02:55.869Z","Name":"Test1","Fat":666,"gameScore":"{'__type': 'Pointer', className: GameScore, objectId: ebqAUbJrKw}","image":"https://picsum.photos/52"}

@phillwiggins
Copy link
Member

I have tested this and it does work. I have a Pointer object in my Parse table, with a mock object in there. A reference to another row in a different table, all works.

@ghost
Copy link

ghost commented Jan 21, 2019

Mmm, can you copy/paste your 2 Model classes please ? Maybe I did something wrong.

@phillwiggins
Copy link
Member

Sent via slack

@MungaraJay
Copy link

MungaraJay commented Aug 14, 2020

I was using parse server sdk in my app for database.

I have three class in my Back4App Dashboard which are "_User", "Office", "Office_Members".

In Office_Members class it has following columns,

  1. user_id (Pointer to _User)
  2. office_id (Pointer to Office)
  3. count

To fetch the data including Pointer to _User as well from Office_Members, I am using following code,

QueryBuilder parseQuery = QueryBuilder(ParseObject("Office_Members"))
..whereEqualTo("office_id", ParseResponse_OfficeObject)
..includeObject(["user_id "]);

ParseResponse apiResponse = await parseQuery.query();

Output :

Payload : [{"className":"Office_Members","objectId":"twpDY51PUK","createdAt":"2020-08-14T09:58:59.775Z","updatedAt":"2020-08-14T09:58:59.775Z","office_id":{"__type":"Pointer","className":"Office","objectId":"4dkfSMrwBI"},"user_id":{"__type":"Pointer","className":"_User","objectId":"Hx5xJ5ABxG"},"count":1}]

In my payload response i am not getting whole user_id pointer response. I have followed the parse sdk server documentation throughout to fire parse queries.

@phillwiggins @scaneat @aBuder So can you help me that what i might be doing wrong?

Thanks.

@aniket453
Copy link

@MungaraJay @phillwiggins @scaneat Did you have any luck with this issue.

I am also getting same kind of issue. I am trying to fetch the values from my "Office" class and in my office class "user_id" column is the Pointer to my User class. So i also want to include user object. I am trying following code

QueryBuilder<ParseObject> parseQuery =
QueryBuilder<ParseObject>(ParseObject("Language"));
parseQuery.includeObject(['user_id']);

ParseResponse parseResponse = await parseQuery.query();

Output i am getting is :

[{"className":" Language ","objectId":"w3U0iHfhkh","createdAt":"2020-08-16T10:23:15.961Z","updatedAt":"2020-08-16T10:23:15.961Z","name":"Lang2199","address":"Address1521","user_id":{"__type":"Pointer","className":"_User","objectId":"zbhsxhpr9x"}}]

Update this thread if anyone finds a solution.

Thanks.

@RodrigoSMarques
Copy link
Contributor

RodrigoSMarques commented Aug 16, 2020

@aniket453
Which version of the plugin are you using?

This works correctly in version 1.0.26

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants