isar / isar/hive

BUG!! save in relationship sometimes work, sometimes doesn't work

Open
#773 1 comment 0 reactions 0 assignees View on GitHub
problem
Dominant language
Dart
Stars
4.4k
Forks
449
PR merge metrics
No merged PRs in 30d

Description

Since 3 days ago that i testing save in relationship, below code some times work, some times doesn't work :| :| :|

```
final _categories = Hive.box('categories');
final _products = Hive.box('products');
final _services = Hive.box('services');

_categories.clear();
_products.clear();
_services.clear();

for (int i = 0; i < 2; i++) {
final _c = _db.Categories()
..title = 'aa'
..categoryId = 1
..image ='sdfsdf';
_categories.add(_c);
_c.products = HiveList(_products);

for (int p = 0; p < 2; p++) {
final _p = _db.Products()
..id = p
..title = 'title'
..image = 'image';
_p.services = HiveList(_services);

for (int k = 0; k < 2; k++) {
final _s = _db.Services()
..id = k
..title = 'title'
..cost = k
..image = 'image';

_services.add(_s);
_p.services.add(_s);
//_s.save();
}

_products.add(_p);
_c.products.add(_p);
//_p.save();
}
_c.save();
}
final _test = Hive.box<_db.Categories>('categories');
print(_test.get(0)!.products.length);
```

i don't get any error and after save in database successful, sometimes when i try to clear and save again, it doesn't work. in this time i don't changed code :|

```
@HiveType(typeId: 5)
class Categories extends HiveObject {
@HiveField(0)
late String title;

@HiveField(1)
late int categoryId;

@HiveField(2)
late String image;

@HiveField(3)
late HiveList products;
}

@HiveType(typeId: 6)
class Products extends HiveObject {
@HiveField(0)
late int id;

@HiveField(1)
late String title;

@HiveField(2)
late String image;

@HiveField(3)
late HiveList services;
}

@HiveType(typeId: 7)
class Services extends HiveObject {
@HiveField(0)
late int id;

@HiveField(1)
late String title;

@HiveField(2)
late int cost;

@HiveField(3)
late String image;
}
```

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.