isar / isar/hive

Can't add to HiveList if HiveObject is in inner collection

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

Description

**Steps to Reproduce**

I want to store a box where key is user ID and value is List of Wallet (every Wallet is a HiveObject).
I also want a user to have a HiveList of its wallets.
The problem is adding to HiveList requires to check if HiveObject is inside of box.
And when I add to box not a HiveObject directly, but a `List`, the `box` property of every HiveObject is null!

**Desired behaviour**: if I put a collection into box, every element should also have a reference to this box in its `box` property

**Code sample**

```dart
Box> walletsBox;
walletsBox = await Hive.openBox>('wallets');

user.wallets = HiveList(walletsBox);

var newWallet = CryptoWallet(address: '1dalrkje;j34;lkj;lkd;35234');
walletsBox.put(userId, [...existingWallets, newWallet]);
user.wallets.add(newWallet); // throws HiveError: HiveObjects needs to be in the box "wallets"
print (newWallet.box); // --> null
```

**Version**
- Platform: Android
- Flutter version: 1.22.6
- Hive version: 1.5.0-pre

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.