Skip to content

array with relations #235

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
aBuder opened this issue Aug 1, 2019 · 2 comments
Closed

array with relations #235

aBuder opened this issue Aug 1, 2019 · 2 comments

Comments

@aBuder
Copy link

aBuder commented Aug 1, 2019

Hi,

how I can get the relations of an array. So I have an user class and this class has field restriction with an array of relations. How I can get the data?

[ { "__type": "Pointer", "className": "Restriction", "objectId": "l15bD1WdrJ" }, { "__type": "Pointer", "className": "Restriction", "objectId": "bD2hGsKetL" } ]

@RodrigoSMarques
Copy link
Contributor

RodrigoSMarques commented Aug 1, 2019

Hi @aBuder .

Try

    final List<ParseObject> restrinctions =
        parseObject.get<List<ParseObject>>(keyFieldName);

    for (final ParseObject restrinction in restrinctions) {
      print(restrinction.objectId);
    }

@aBuder
Copy link
Author

aBuder commented Aug 2, 2019

@RodrigoSMarques

I found an solution.

That breaks

List<ParseObject> restrictions = [];

void fetchRestrictions() async {
    List<ParseObject> restrictions = user?.get<List<ParseObject>>('restriction');
    this.restrictions = restrictions;
}

Log

The application is paused in the debugger after an exception was thrown.
Reloaded 7 of 704 libraries.
[VERBOSE-2:shell.cc(184)] Dart Error: Unhandled exception:
type 'List<dynamic>' is not a subtype of type 'List<ParseObject>'
#0      UserProvider.fetchRestrictions (package:trainer/provider/user_provider.dart:34:24)
<asynchronous suspension>
#1      new UserProvider (package:trainer/provider/user_provider.dart:14:5)
#2      UsersScreen.build.<anonymous closure>.<anonymous closure>.<anonymous closure> (package:trainer/screen/users/users_screen.dart:111:30)
#3      MaterialPageRoute.buildPage (package:flutter/src/material/page.dart:87:27)
#4      _ModalScopeState.build.<anonymous closure> (package:flutter/src/widgets/routes.dart:666:43)
#5      Builder.build (package:flutter/src/widgets/basic.dart:6427:41)
#6      StatelessElement.build (package:flutter/src/widgets/framework.dart:3974:28)
#7      ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3924:15)
#8      Element.rebuild (package:flutter/src/widgets/framework.dart:3721:5)
#9      StatelessElement.update (package:flutter<…>

The following code works very well :-)

List<ParseObject> restrictions = [];

void fetchRestrictions() async {
    final restrictions = user?.get<List<ParseObject>>('restriction');
    this.restrictions.clear();
    for (final ParseObject restriction in restrictions) {
      this.restrictions.add(restriction);
    }
}

@aBuder aBuder closed this as completed Aug 8, 2019
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