Skip to content

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

@WalterWoshid

Description

@WalterWoshid

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

Metadata

Metadata

Assignees

Labels

datastoreIssues related to the DataStore Categoryfeature-requestA request for a new feature or an enhancement to an existing API or category.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions