Skip to content
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

Self-referencing relationships gives error, hasMany self referencing #2534

Closed
2 tasks done
MarlonJD opened this issue May 8, 2024 · 6 comments
Closed
2 tasks done
Assignees
Labels
bug Something isn't working Gen 2 pending-release

Comments

@MarlonJD
Copy link

MarlonJD commented May 8, 2024

How did you install the Amplify CLI?

npm

If applicable, what version of Node.js are you using?

v21.5.0

Amplify CLI Version

1.0.1

What operating system are you using?

MacOS

Did you make any manual changes to the cloud resources managed by Amplify? Please describe the changes made.

No

Describe the bug

When I try to create self-referenced models, it gives error:

Model:

Task: a
  .model({
    content: a.string(),
    parentId: a.id(),
    parent: a.belongsTo('Task', "parentId"),
    children: a.hasMany('Task', "parentId"),
  }).authorization((allow) => [allow.guest()]),

Error on npx ampx sandbox

Failed to instantiate data construct
Caused By: Uni-directional relationships are not supported. Add a @belongsTo field in Task to match the @hasMany field Task.children

Resolution: See the underlying error message for more details.

Expected behavior

It should work properly, it was working before update

Reproduction steps

Create Task model with these:

Task: a
  .model({
    content: a.string(),
    parentId: a.id(),
    parent: a.belongsTo('Task', "parentId"),
    children: a.hasMany('Task', "parentId"),
  }).authorization((allow) => [allow.guest()]),

and try to generate models npx ampx sandbox

Project Identifier

No response

Log output

# Put your logs below this line


Additional information

No response

Before submitting, please confirm:

  • I have done my best to include a minimal, self-contained set of instructions for consistently reproducing the issue.
  • I have removed any sensitive information from my code snippets and submission.
@AnilMaktala
Copy link

Hi @MarlonJD, Thank you for raising this. We can replicate the issue by using the Schema in the description. Hence, Marking this as a bug for the team to evaluate further.

image

@AnilMaktala AnilMaktala added bug Something isn't working and removed pending-triage labels May 8, 2024
@MarlonJD
Copy link
Author

MarlonJD commented May 8, 2024

Here are the more info about the versions, thanks @JonasRothSwinx for clarification about this.

"@aws-amplify/backend": "^0.13.4"
"@aws-amplify/backend-cli": "^0.12.1"

The previously working beta:

"@aws-amplify/backend": "^0.13.0-beta.20",
"@aws-amplify/backend-cli": "^0.12.0-beta.22",

BTW, It seems it's related to gen2 amplify-backend repo, is this good idea to create issue on https://github.com/aws-amplify/amplify-backend ?

@AnilMaktala
Copy link

@MarlonJD This repository is the correct one for addressing this issue.

@MarlonJD
Copy link
Author

MarlonJD commented May 9, 2024

PR #2533 should fix this issue, I'll close when it released, thanks!

@palpatim palpatim self-assigned this May 9, 2024
@renebrandel
Copy link
Contributor

Confirming this is released.

Copy link

This issue is now closed. Comments on closed issues are hard for our team to see.
If you need more assistance, please open a new issue that references this one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working Gen 2 pending-release
Projects
None yet
Development

No branches or pull requests

4 participants