HiveObjects needs to be in the box
- Dominant language
- Dart
- Stars
- 4.4k
- Forks
- 449
- PR merge metrics
- No merged PRs in 30d
Description
I have defined two boxes in `Hive` as follows:
```dart
@HiveType(typeId: 1)
class CartTable extends HiveObject {
@HiveField(0)
late int id;
@HiveField(1)
late String name;
@HiveField(2)
late String image;
@HiveField(3)
late HiveList orders;
}
@HiveType(typeId: 2)
class OrdersTable extends HiveObject {
@HiveField(0)
late int id;
@HiveField(1)
late String name;
@HiveField(2)
late String description;
@HiveField(3)
late int price;
@HiveField(4)
late String image;
@HiveField(5,defaultValue: '')
String? detail;
@HiveField(6,defaultValue: '')
String? note;
@HiveField(7,defaultValue: 1)
late int count;
@HiveField(8,defaultValue: '')
String? promotionCode;
}
```
Note:
Inside the `CartTable` box, there is another box named `OrdersTable` which should have a relationship with each other.
And I opened these two boxes in the `main.dart` file as follows:
```dart
await Hive.openBox('cart', encryptionCipher: HiveAesCipher(key));
await Hive.openBox('orders', encryptionCipher: HiveAesCipher(key));
```
Now, when I try to establish this relationship with the following code, it gives me the following error:
HiveObjects needs to be in the box 'orders'.
Here are the implemented codes:
```dart
Box _cartTable= Hive.box('cart');
Box _orders = Hive.box('orders');
CartTable? cart;
cart = CartTable()
..id = store.id
..name = store.name
..image = store.image;
cart.orders = HiveList(_orders);
final order = OrdersTable()
..id = menu.id
..name = menu.name
..description = menu.description!
..image = menu.image
..price = menu.price
..note=''
..detail=''
..promotionCode=''
..count = 1;
cart.orders.add(order);
cartTable.add(cart);
cart.save();
```
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.