Skip to content

Commit

Permalink
Fix Prefetching references docs
Browse files Browse the repository at this point in the history
  • Loading branch information
AhmedLSayed9 authored and simolus3 committed Oct 28, 2024
1 parent 97e16fd commit e92c32b
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions docs/lib/snippets/dart_api/manager.dart
Original file line number Diff line number Diff line change
Expand Up @@ -230,22 +230,22 @@ extension ManagerExamples on AppDatabase {
// #docregion manager_prefetch_references
Future<void> referencesPrefetch() async {
/// Get each todo, along with a its categories
final categoriesWithReferences = await managers.todoItems
final todosWithRefs = await managers.todoItems
.withReferences(
(prefetch) => prefetch(category: true),
)
.get();
for (final (todo, refs) in categoriesWithReferences) {
for (final (todo, refs) in todosWithRefs) {
final category = refs.category?.prefetchedData?.firstOrNull;
// No longer needed
// final category = await refs.category?.getSingle();
}

/// This also works in the reverse
final todosWithRefs = await managers.todoCategory
final categoriesWithRefs = await managers.todoCategory
.withReferences((prefetch) => prefetch(todoItemsRefs: true))
.get();
for (final (category, refs) in todosWithRefs) {
for (final (category, refs) in categoriesWithRefs) {
final todos = refs.todoItemsRefs.prefetchedData;
// No longer needed
//final todos = await refs.todoItemsRefs.get();
Expand Down

0 comments on commit e92c32b

Please sign in to comment.