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

Relation cannot be saved by model, only by ID #1451

Closed
2 of 9 tasks
WalterWoshid opened this issue Mar 11, 2022 · 9 comments
Closed
2 of 9 tasks

Relation cannot be saved by model, only by ID #1451

WalterWoshid opened this issue Mar 11, 2022 · 9 comments
Assignees
Labels
datastore Issues related to the DataStore Category feature-request A request for a new feature or an enhancement to an existing API or category.

Comments

@WalterWoshid
Copy link

WalterWoshid commented Mar 11, 2022

Description

Trying to save a model with a relationship only works when saving by ID like this

Wallet newWallet = Wallet(
  data: data,
);
user = user.copyWith(
  userWalletId: newWallet.id,
);
await Amplify.DataStore.save(newWallet);
await Amplify.DataStore.save(user);

Expected behaviour, like in the docs:

Wallet newWallet = Wallet(
  data: data,
);
user = user.copyWith(
  Wallet: newWallet, // THIS DOES NOT WORK
);
await Amplify.DataStore.save(newWallet); // Saves the new wallet successfully
await Amplify.DataStore.save(user); // Doesn't add the relation to the user

No error is returned, it just doesn't save the relation

Categories

  • Analytics
  • API (REST)
  • API (GraphQL)
  • Auth
  • Authenticator
  • DataStore
  • Storage

Steps to Reproduce

No response

Screenshots

No response

Platforms

  • iOS
  • Android

Environment

Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 2.8.1, on Microsoft Windows [Version 10.0.19044.1586], locale de-DE)
[✓] Android toolchain - develop for Android devices (Android SDK version 31.0.0)
[✓] Chrome - develop for the web
[✓] Android Studio (version 2021.1)
[✓] VS Code (version 1.65.1)
[✓] Connected device (4 available)

• No issues found!

Dependencies

Dart SDK 2.15.1
Flutter SDK 2.8.1
remonon 0.2.3+28

dependencies:
- amplify_api 0.3.2 [amplify_api_plugin_interface amplify_core flutter plugin_platform_interface]
- amplify_auth_cognito 0.3.2 [flutter amplify_auth_plugin_interface amplify_core collection plugin_platform_interface]
- amplify_datastore 0.3.2 [flutter amplify_datastore_plugin_interface amplify_core plugin_platform_interface meta collection async]
- amplify_flutter 0.3.2 [amplify_analytics_plugin_interface amplify_api_plugin_interface amplify_auth_plugin_interface amplify_core amplify_datastore_plugin_interface amplify_storage_plugin_interface collection flutter json_annotation meta plugin_platform_interface]
- amplify_storage_s3 0.3.2 [flutter amplify_storage_plugin_interface plugin_platform_interface amplify_core]
- camera 0.9.4+14 [camera_platform_interface camera_web flutter flutter_plugin_android_lifecycle quiver]
- cupertino_icons 1.0.4
- dotted_border 2.0.0+2 [flutter path_drawing]
- equatable 2.0.3 [collection meta]
- file_picker 4.5.0 [flutter flutter_web_plugins flutter_plugin_android_lifecycle plugin_platform_interface ffi path win32]
- file_saver 0.0.12 [flutter flutter_web_plugins path_provider path_provider_linux path_provider_windows]
- flutter 0.0.0 [characters collection meta typed_data vector_math sky_engine]
- flutter_bloc 7.3.3 [flutter bloc provider]
- flutter_local_notifications 9.4.0 [clock flutter flutter_local_notifications_linux flutter_local_notifications_platform_interface timezone]
- http 0.13.4 [async http_parser meta path]
- image_cropping 0.0.9 [flutter image cupertino_icons]
- image_picker 0.8.4+10 [flutter flutter_plugin_android_lifecycle image_picker_for_web image_picker_platform_interface]
- intl 0.17.0 [clock path]
- lint 1.8.2
- loader_overlay 2.0.5+1 [flutter back_button_interceptor]
- local_auth 1.1.11 [flutter flutter_plugin_android_lifecycle intl platform]
- open_file 3.2.1 [flutter ffi]
- package_info_plus 1.4.0 [flutter package_info_plus_platform_interface package_info_plus_linux package_info_plus_macos package_info_plus_windows package_info_plus_web]
- path_provider 2.0.9 [flutter path_provider_android path_provider_ios path_provider_linux path_provider_macos path_provider_platform_interface path_provider_windows]
- pdf_viewer_plugin 2.0.1 [flutter pedantic]
- photo_view 0.13.0 [flutter]
- pin_code_fields 7.3.0 [flutter]
- provider 6.0.2 [collection flutter nested]
- pull_to_refresh 2.0.0 [flutter]
- timezone 0.8.0 [path]
- uni_links 0.5.1 [flutter uni_links_platform_interface uni_links_web]
- url_launcher 6.0.20 [flutter url_launcher_android url_launcher_ios url_launcher_linux url_launcher_macos url_launcher_platform_interface url_launcher_web url_launcher_windows]
- veriff_flutter 2.1.0 [flutter]

transitive dependencies:
- amplify_analytics_plugin_interface 0.3.2 [amplify_core flutter meta]
- amplify_api_plugin_interface 0.3.2 [amplify_core collection flutter json_annotation meta]
- amplify_auth_plugin_interface 0.3.2 [flutter meta amplify_core]
- amplify_core 0.3.2 [flutter meta plugin_platform_interface uuid]
- amplify_datastore_plugin_interface 0.3.2 [flutter meta collection date_time_format uuid amplify_core]
- amplify_storage_plugin_interface 0.3.2 [flutter meta amplify_core]
- archive 3.2.1 [crypto path]
- args 2.3.0
- async 2.8.2 [collection meta]
- back_button_interceptor 5.0.2 [collection flutter]
- bloc 7.2.1 [meta]
- camera_platform_interface 2.1.5 [cross_file flutter plugin_platform_interface stream_transform]
- camera_web 0.2.1+3 [camera_platform_interface flutter flutter_web_plugins stream_transform]
- characters 1.2.0
- charcode 1.3.1
- clock 1.1.0
- collection 1.15.0
- cross_file 0.3.2 [flutter js meta]
- crypto 3.0.1 [collection typed_data]
- date_time_format 2.0.1
- dbus 0.7.1 [args ffi meta xml]
- ffi 1.1.2
- file 6.1.2 [meta path]
- flutter_local_notifications_linux 0.4.2 [flutter flutter_local_notifications_platform_interface dbus path xdg_directories]
- flutter_local_notifications_platform_interface 5.0.0 [flutter plugin_platform_interface]
- flutter_plugin_android_lifecycle 2.0.5 [flutter]
- flutter_web_plugins 0.0.0 [flutter js characters collection meta typed_data vector_math]
- http_parser 4.0.0 [charcode collection source_span string_scanner typed_data]
- image 3.1.3 [archive meta xml]
- image_picker_for_web 2.1.6 [flutter flutter_web_plugins image_picker_platform_interface]
- image_picker_platform_interface 2.4.4 [cross_file flutter http plugin_platform_interface]
- js 0.6.3
- json_annotation 4.4.0 [meta]
- matcher 0.12.11 [stack_trace]
- meta 1.7.0
- nested 1.0.0 [flutter]
- package_info_plus_linux 1.0.3 [package_info_plus_platform_interface flutter path]
- package_info_plus_macos 1.3.0 [flutter]
- package_info_plus_platform_interface 1.0.2 [flutter meta plugin_platform_interface]
- package_info_plus_web 1.0.4 [flutter flutter_web_plugins http meta package_info_plus_platform_interface]
- package_info_plus_windows 1.0.4 [package_info_plus_platform_interface ffi flutter win32]
- path 1.8.0
- path_drawing 1.0.0 [vector_math meta path_parsing flutter]
- path_parsing 1.0.0 [vector_math meta]
- path_provider_android 2.0.12 [flutter path_provider_platform_interface]
- path_provider_ios 2.0.8 [flutter path_provider_platform_interface]
- path_provider_linux 2.1.5 [ffi flutter path path_provider_platform_interface xdg_directories]
- path_provider_macos 2.0.5 [flutter path_provider_platform_interface]
- path_provider_platform_interface 2.0.3 [flutter platform plugin_platform_interface]
- path_provider_windows 2.0.5 [ffi flutter path path_provider_platform_interface win32]
- pedantic 1.11.1
- petitparser 4.4.0 [meta]
- platform 3.1.0
- plugin_platform_interface 2.1.2 [meta]
- process 4.2.4 [file path platform]
- quiver 3.0.1+1 [matcher]
- sky_engine 0.0.99
- source_span 1.8.1 [collection path term_glyph]
- stack_trace 1.10.0 [path]
- stream_transform 2.0.0
- string_scanner 1.1.0 [charcode source_span]
- term_glyph 1.2.0
- typed_data 1.3.0 [collection]
- uni_links_platform_interface 1.0.0 [flutter plugin_platform_interface]
- uni_links_web 0.1.0 [flutter flutter_web_plugins uni_links_platform_interface]
- url_launcher_android 6.0.15 [flutter url_launcher_platform_interface]
- url_launcher_ios 6.0.15 [flutter url_launcher_platform_interface]
- url_launcher_linux 3.0.0 [flutter url_launcher_platform_interface]
- url_launcher_macos 3.0.0 [flutter url_launcher_platform_interface]
- url_launcher_platform_interface 2.0.5 [flutter plugin_platform_interface]
- url_launcher_web 2.0.6 [flutter flutter_web_plugins url_launcher_platform_interface]
- url_launcher_windows 3.0.0 [flutter url_launcher_platform_interface]
- uuid 3.0.6 [crypto]
- vector_math 2.1.1
- win32 2.4.1 [ffi]
- xdg_directories 0.2.0+1 [meta path process]
- xml 5.3.1 [collection meta petitparser]

Device

Pixel 4 API 31

OS

Android 12.0

CLI Version

7.6.23

Additional Context

No response

@Jordan-Nelson Jordan-Nelson added datastore Issues related to the DataStore Category pending-triage This issue is in the backlog of issues to triage labels Mar 11, 2022
@Jordan-Nelson
Copy link
Member

Hi @WalterWoshid - Can you share your schema? Or at least a subset that includes the user/wallet models. Thanks.

@Jordan-Nelson Jordan-Nelson added the pending-community-response Pending response from the issue opener or other community members label Mar 11, 2022
@WalterWoshid
Copy link
Author

WalterWoshid commented Mar 11, 2022

Hi @Jordan-Nelson

here you go:

backend/api/app/schema.graphql:

type Wallet @model @auth(rules: [{allow: private}]) {
  id: ID!
  data: String
}

type User @model @auth(rules: [{allow: owner}, {allow: public, operations: [create, read, update]}, {allow: groups, groups: ["admin"], operations: [read, create, update, delete]}]) {
  id: ID!
  Veriff: VeriffModel @hasOne
}

#current-cloud-backend/api/app/build/schema.graphql

type Wallet @aws_iam @aws_cognito_user_pools {
  id: ID!
  data: String
  createdAt: AWSDateTime!
  updatedAt: AWSDateTime!
  _version: Int!
  _deleted: Boolean
  _lastChangedAt: AWSTimestamp!
}

type User @aws_api_key @aws_iam @aws_cognito_user_pools {
  id: ID!
  Wallet: Wallet
  createdAt: AWSDateTime!
  updatedAt: AWSDateTime!
  _version: Int!
  _deleted: Boolean
  _lastChangedAt: AWSTimestamp!
  userWalletId: ID
}

@Jordan-Nelson
Copy link
Member

In backend/api/app/schema.graphql does User have a connection to Wallet?

@HuiSF
Copy link
Member

HuiSF commented Mar 11, 2022

FWIW, this is a limitation for hasOne relationship cross Amplify libraries, that when associate the model for hasOne relationship, would need to assign the connection ID filed directly (what shown in your first code sample).

I think this limitation will be removed along with the initiative of #1449 - better experience on cascade save and delete.

@WalterWoshid
Copy link
Author

@Jordan-Nelson It does not seem like it. The only ModelWalletConnection is for listWallets and syncWallets in type Query {}

@HuiSF Looking forward for the new update :)

@Jordan-Nelson Jordan-Nelson removed the pending-community-response Pending response from the issue opener or other community members label Mar 14, 2022
@Jordan-Nelson
Copy link
Member

@HuiSF - Do you want to track this as part of #1449, or keep this open to track it separately?

@HuiSF
Copy link
Member

HuiSF commented Mar 14, 2022

amplify-ios team is looking into a solution as well - aws-amplify/amplify-swift#1676

@HuiSF
Copy link
Member

HuiSF commented Mar 14, 2022

@HuiSF - Do you want to track this as part of #1449, or keep this open to track it separately?

I think we can keep this issue open, as amplify-ios and amplify-android may have started looking into a solution that could be delivered before #1449

I will keep following the progress and update here.

@HuiSF HuiSF added requires-android-fix This issue is the result of an underlying Amplify Android issue that needs to be fixed. requires-ios-fix This issue is the result of an underlying Amplify iOS issue that needs to be fixed. bug Something is not working; the issue has reproducible steps and has been reproduced labels Mar 14, 2022
@Jordan-Nelson Jordan-Nelson removed the pending-triage This issue is in the backlog of issues to triage label Mar 21, 2022
@HuiSF HuiSF added feature-request A request for a new feature or an enhancement to an existing API or category. and removed bug Something is not working; the issue has reproducible steps and has been reproduced requires-android-fix This issue is the result of an underlying Amplify Android issue that needs to be fixed. requires-ios-fix This issue is the result of an underlying Amplify iOS issue that needs to be fixed. labels Mar 30, 2022
@HuiSF
Copy link
Member

HuiSF commented Mar 30, 2022

This is a known feature gap between model relationship support, which will be resolved with #1449.
Closing this issue as a duplicate and we will post updates in the linked issue. Please feel free to follow up on the main feature request issue. Thanks.

@HuiSF HuiSF closed this as completed Mar 30, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
datastore Issues related to the DataStore Category feature-request A request for a new feature or an enhancement to an existing API or category.
Projects
None yet
Development

No branches or pull requests

3 participants