Skip to content

Commit 2f3b0be

Browse files
Copilotpawcoding
andcommitted
docs: add documentation for expand parameter in live loader
Co-authored-by: pawcoding <[email protected]>
1 parent 443273d commit 2f3b0be

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed

README.md

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,52 @@ const blogLive = defineLiveCollection({
309309
});
310310
```
311311

312+
### Expanding relations
313+
314+
The live loader supports expanding relation fields directly in the API request, which will include the related records in the response.
315+
This is useful when you need to access related data without making additional requests.
316+
317+
```ts
318+
const blogLive = defineLiveCollection({
319+
loader: experimentalPocketbaseLiveLoader({
320+
...options,
321+
experimental: {
322+
// Expand single relation field
323+
expand: ["author"]
324+
325+
// Expand multiple relation fields
326+
expand: ["author", "category"]
327+
328+
// Expand nested relations (up to 6 levels deep)
329+
expand: ["author.profile", "category.parent"]
330+
}
331+
})
332+
});
333+
```
334+
335+
When you fetch entries with expanded relations, the related records will be available in the `expand` property:
336+
337+
```ts
338+
const entry = await getLiveEntry("blogLive", { id: "<entry-id>" });
339+
340+
// Access expanded relation data
341+
console.log(entry.expand.author.name);
342+
console.log(entry.expand.category.name);
343+
344+
// Access nested expanded relations
345+
console.log(entry.expand.author.expand.profile.bio);
346+
```
347+
348+
> [!NOTE]
349+
> The expand parameter:
350+
>
351+
> - Supports up to 6 levels of nested relations (enforced by PocketBase)
352+
> - Must use separate array entries for each field (e.g., `["author", "category"]` not `["author,category"]`)
353+
> - Is not compatible with the `fields` option
354+
> - Does not support schema generation yet - expanded data will have `unknown` types
355+
>
356+
> For more details on the expand syntax, see the [PocketBase documentation](https://pocketbase.io/docs/collections/#expand-relation-fields).
357+
312358
### Error handling
313359

314360
The live content loader follows Astro's standard error handling conventions for live collections. For more information on how to handle errors in your components, see the [Astro documentation on error handling](https://docs.astro.build/en/reference/experimental-flags/live-content-collections/#error-handling).

0 commit comments

Comments
 (0)