Skip to content

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

Closed
catalunha opened this issue Nov 26, 2022 · 5 comments
Closed

getRelation with error: Invalid Relation key name #801

catalunha opened this issue Nov 26, 2022 · 5 comments
Labels
type:question Support or code-level question

Comments

@catalunha
Copy link

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.

    log('addRelation 01');
    final parseObjectBook01 = ParseObject(BookEntity.className);
    parseObjectBook01.objectId = 'aeOTTuGO7r';
    final parseObjectAuthor01 = ParseObject(AuthorEntity.className);
    parseObjectAuthor01.objectId = 'fK4I00NlBy';
    parseObjectBook01.addRelation('typeRelationAuthor', [parseObjectAuthor01]);
    await parseObjectBook01.save();

But this code. It generates error. Informed below.

    log('addRelation 01a');
    final parseObjectBook01 = ParseObject(BookEntity.className);
    parseObjectBook01.objectId = 'aeOTTuGO7r';
    var parseRelationBook = parseObjectBook01.getRelation('typeRelationAuthor');
    final parseObjectAuthor01 = ParseObject(AuthorEntity.className);
    parseObjectAuthor01.objectId = 'fK4I00NlBy';
    parseRelationBook.add(parseObjectAuthor01);
    await parseObjectBook01.save();

image
Exactly on this line:
var parseRelationBook = parseObjectBook01.getRelation('typeRelationAuthor');
image

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

  • SDK version: parse_server_sdk_flutter: ^3.1.3
  • Operating system version: Description: Pop!_OS 22.04 LTS

Server

  • Parse Server version: 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)

@parse-github-assistant
Copy link

Thanks for opening this issue!

  • ❌ Please edit your post and use the provided template when creating a new issue. This helps everyone to understand your post better and asks for essential information to quicker review the issue.

@mtrezza mtrezza added the type:bug Impaired feature or lacking behavior that is likely assumed label Nov 27, 2022
@catalunha
Copy link
Author

Congratulations and thanks @mtrezza ,
I wish I had more knowledge to solve issues and not just create them.
I'm struggling here.

@mbfakourii
Copy link
Member

mbfakourii commented Nov 27, 2022

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');

@catalunha
Copy link
Author

It is true @mbfakourii
Sorry for the inconvenience and thanks for the help.
I thought that only for addition it made association and allowed addition.

@catalunha
Copy link
Author

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();
  }

@mtrezza mtrezza added type:question Support or code-level question and removed type:bug Impaired feature or lacking behavior that is likely assumed labels Nov 27, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type:question Support or code-level question
Projects
None yet
Development

No branches or pull requests

3 participants