-
-
Notifications
You must be signed in to change notification settings - Fork 206
getRelation with error: Invalid Relation key name #801
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
Comments
Thanks for opening this issue!
|
Congratulations and thanks @mtrezza , |
You have created an empty parseObject and you are trying to get the value but your key does not exist in the empty ParseObject ! I suggest first fetch and next try getRelation. like this var parseObjectBook01 = ParseObject(BookEntity.className);
parseObjectBook01.objectId = 'aeOTTuGO7r';
parseObjectBook01 = await parseObjectBook01.fetch(); // <--------
var parseRelationBook = parseObjectBook01.getRelation('typeRelationAuthor'); |
It is true @mbfakourii |
Final code follows. static addRelations() async {
log('addRelation 01');
//The downside of this approach is that it fetches the data.
var parseObjectBook01 = ParseObject(BookEntity.className);
parseObjectBook01.objectId = 'aeOTTuGO7r';
parseObjectBook01 = await parseObjectBook01.fetch();
var parseRelationBook = parseObjectBook01.getRelation('typeRelationAuthor');
print(parseRelationBook.toJson());
print(parseRelationBook.toString());
final parseObjectAuthor01 = ParseObject(AuthorEntity.className);
parseObjectAuthor01.objectId = 'fK4I00NlBy';
parseRelationBook.add(parseObjectAuthor01);
await parseObjectBook01.save();
log('addRelation 02');
final parseObjectBook02 = ParseObject(BookEntity.className);
parseObjectBook02.objectId = 'gkotvO6IKI';
final parseObjectAuthor02 = ParseObject(AuthorEntity.className);
parseObjectAuthor02.objectId = 'ETwKYOAMh2';
parseObjectBook02.addRelation(
'typeRelationAuthor', [parseObjectAuthor01, parseObjectAuthor02]);
await parseObjectBook02.save();
} |
I'm building a tutorial for Parse Serve (using Back4app) and ran into this issue on SKD for Flutter.
New Issue Checklist
Issue Description
I tested the following code. All very well.
But this code. It generates error. Informed below.
Exactly on this line:
var parseRelationBook = parseObjectBook01.getRelation('typeRelationAuthor');
Steps to reproduce
Create a pure standard Dart project with VSCode
Create a basic project in back4app and write down the appId and clientKey.
Copy the code above to your Dart project and enter the correct appId and clientKey and then a wrong value.
Run the Dart project with:
$ dart bin/learning_about_b4a_dart.dart
Actual Outcome
Error
Expected Outcome
May the result be the same. In both codes
Environment
Parse Flutter SDK
Server
4.5.0
Logs
Connecting to VM Service at http://127.0.0.1:35555/jjn-YZQ6Y-s=/
[log] Back4app Connected.
[log] addRelation 01a
Unhandled exception:
Invalid Relation key name
#0 new ParseRelation
package:parse_server_sdk/…/objects/parse_relation.dart:7
#1 ParseObject.getRelation
package:parse_server_sdk/…/objects/parse_object.dart:313
#2 BookAddData.addRelations2
package:learning_about_b4a_dart/…/book/book_add_data.dart:108
#3 main
bin/learning_about_b4a_dart.dart:81
Exited (255)
The text was updated successfully, but these errors were encountered: