objectbox / objectbox-dart

Flutter database for super-fast Dart object persistence
https://docs.objectbox.io/getting-started
Apache License 2.0
981 stars 119 forks source link

when build_runner show error "Unknown relation“, the object define @Backlink. #296

Closed nodelinker closed 2 years ago

nodelinker commented 2 years ago

Basic info (please complete the following information):

ObjectBox version: [e.g. 1.1.1]

> Doctor summary (to see all details, run flutter doctor -v):
> [√] Flutter (Channel stable, 2.2.3, on Microsoft Windows [Version 10.0.19042.1110], locale zh-CN)
> [√] Android toolchain - develop for Android devices (Android SDK version 30.0.3)
> [√] Chrome - develop for the web
> [√] Android Studio (version 4.1.0)
> [√] VS Code (version 1.59.0)
> [√] Connected device (3 available)
> 
> • No issues found!

> Dart SDK 2.13.4
> Flutter SDK 2.2.3
> object_example 1.0.0+1
> |-- cupertino_icons 1.0.3
> |-- flutter 0.0.0
> |   |-- characters 1.1.0
> |   |-- collection 1.15.0
> |   |-- meta 1.3.0
> |   |-- sky_engine 0.0.99
> |   |-- typed_data 1.3.0
> |   |   '-- collection...
> |   '-- vector_math 2.1.0
> |-- objectbox 1.1.1
> |   |-- collection...
> |   |-- ffi 1.1.2
> |   |-- meta...
> |   '-- path...
> |-- objectbox_flutter_libs 1.1.1
> |   |-- objectbox...
> |   '-- path_provider...
> |-- path 1.8.0
> |-- path_provider 2.0.2
> |   |-- flutter...
> |   |-- path_provider_linux 2.0.2
> |   |   |-- flutter...
> |   |   |-- path...
> |   |   |-- path_provider_platform_interface...
> |   |   '-- xdg_directories 0.2.0
> |   |       |-- meta...
> |   |       |-- path...
> |   |       '-- process 4.2.3
> |   |           |-- file 6.1.2
> |   |           |   |-- meta...
> |   |           |   '-- path...
> |   |           |-- path...
> |   |           '-- platform...
> |   |-- path_provider_macos 2.0.2
> |   |   '-- flutter...
> |   |-- path_provider_platform_interface 2.0.1
> |   |   |-- flutter...
> |   |   |-- meta...
> |   |   |-- platform 3.0.0
> |   |   '-- plugin_platform_interface 2.0.1
> |   |       '-- meta...
> |   '-- path_provider_windows 2.0.3
> |       |-- ffi...
> |       |-- flutter...
> |       |-- meta...
> |       |-- path...
> |       |-- path_provider_platform_interface...
> |       '-- win32 2.2.5
> |           '-- ffi...
> '-- provider 5.0.0
>     |-- collection...
>     |-- flutter...
>     '-- nested 1.0.0
>         '-- flutter...

Steps to reproduce

  1. Put '...'
  2. Make changes to '....'
  3. See error

Expected behavior

A clear and concise description of what you expected to happen.

Code

copy from document https://docs.objectbox.io/relations

> @Entity()
> class Customer {
>   int id;
> 
>   // target-field argument is optional if only one relation matches.
>   @Backlink('customer')
>   final orders = ToMany\<Order\>();
> 
>   Customer({this.id = 0});
> }
> 
> @Entity()
> class Order {
>   int id;
> 
>   final customer = ToOne\<Customer\>();
> 
>   Order({this.id = 0});
> }
> 
> 

Logs, stack traces

flutter pub run build_runner build

> [INFO] Generating build script...
> [INFO] Generating build script completed, took 448ms
> 
> [INFO] Initializing inputs
> [INFO] Reading cached asset graph...
> [INFO] Reading cached asset graph completed, took 69ms
> 
> [INFO] Checking for updates since last build...
> [INFO] Checking for updates since last build completed, took 776ms
> 
> [INFO] Running build...
> [INFO] Running build completed, took 21ms
> 
> [INFO] Caching finalized dependency graph...
> [INFO] Caching finalized dependency graph completed, took 48ms
> 
> [SEVERE] objectbox_generator:generator on lib/$lib$ (cached):
> 
> Unknown relation backlink source for Customer.orders
> [SEVERE] Failed after 92ms
> pub finished with exit code 1
greenrobot-team commented 2 years ago

Thanks for reporting. Confirmed it does not work if the backlink source is a ToOne. Using to does work if the backlink source is a ToMany.

@nodelinker As a workaround until there is a fix, try to remove the to name and just use @Backlink().