isar / isar/hive

Values in HiveList are lost

Open
#208 2 comments 1 reaction 1 assignee Claimed by @simc View on GitHub
documentation question
Dominant language
Dart
Stars
4.4k
Forks
449
PR merge metrics
No merged PRs in 30d

Description

**Steps to Reproduce**
See below.

**Code sample**
This is an extract from the [Relationships](https://docs.hivedb.dev/#/custom-objects/relationships) section of hive docs.

```dart
void main() async {
Hive.registerAdapter(PersonAdapter());
var persons = await Hive.openBox('personsWithLists');
persons.clear();

var mario = Person('Mario');
var luna = Person('Luna');
var alex = Person('Alex');
persons.addAll([mario, luna, alex]);

mario.friends = HiveList(persons); // Create a HiveList
mario.friends.addAll([luna, alex]); // Update Mario's friends
print(mario.friends);

luna.delete(); // Remove Luna from Hive
print(mario.friends); // HiveList updates automatically
}
```

The last line outputs `[alex]`, meaning HiveList (`mario.friends`) holds a value in it.
I thought the value would be stored in the .hive file and the next code would still output `[alex]`, but actually resulted in `[]`.

```dart
void main() async {
Hive.registerAdapter(PersonAdapter());
var persons = await Hive.openBox('personsWithLists');

var mario = persons.getAt(0);
mario.friends = HiveList(persons);
print(mario); // Mario
print(mario.friends); // []
}
```
Is it an expected behaviour?
Commenting out the line of `mario.friends = HiveList(persons);` in the second code did not affect the result.

**Version**
- Platform: Windows
- Flutter version: N/A (Dart only)
- Hive version: 1.3.0

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.