✨ feat: unify API options structure and enhance lookup handling across collections
This commit is contained in:
@@ -522,19 +522,14 @@ Test setup:
|
||||
|
||||
## API lookup für aufgelöste Referenzen
|
||||
|
||||
Beim Laden von Collections können Fremdschlüssel via `lookup`-Parameter automatisch aufgelöst werden. Der `lookup`-Parameter wird als 8. Argument an `getCachedEntries` übergeben:
|
||||
Beim Laden von Collections können Fremdschlüssel via `lookup`-Parameter automatisch aufgelöst werden. Der `lookup`-Parameter wird einfach im Optionen-Objekt an `getCachedEntries` übergeben:
|
||||
|
||||
```ts
|
||||
const products = await getCachedEntries<"machines">(
|
||||
"machines",
|
||||
{ active: true, category: catId },
|
||||
"sortOrder",
|
||||
undefined,
|
||||
undefined,
|
||||
undefined,
|
||||
undefined,
|
||||
"images:medialib" // lookup: "feld:collection"
|
||||
)
|
||||
const products = await getCachedEntries<"machines">("machines", {
|
||||
filter: { active: true, category: catId },
|
||||
sort: "sortOrder",
|
||||
lookup: "images:medialib", // lookup: "feld:collection"
|
||||
})
|
||||
```
|
||||
|
||||
Das Format ist `"feldname:zielcollection"` (z.B. `"images:medialib"`). Die aufgelösten Daten landen in `entry._lookup.feldname` als Array der Ziel-Collection-Objekte. Ohne lookup bleiben `string[]`-Felder reine ID-Arrays.
|
||||
|
||||
@@ -126,19 +126,14 @@ Typical usage:
|
||||
For repeated collection data such as galleries, teaser lists, or detail-page image arrays, also request the lookup instead of rendering from raw ID strings:
|
||||
|
||||
```ts
|
||||
const entries = await getCachedEntries<CollectionName>(
|
||||
"your-collection",
|
||||
{ active: true },
|
||||
"sortOrder",
|
||||
undefined,
|
||||
undefined,
|
||||
undefined,
|
||||
undefined,
|
||||
"imageField:medialib"
|
||||
)
|
||||
const entries = await getCachedEntries<CollectionName>("your-collection", {
|
||||
filter: { active: true },
|
||||
sort: "sortOrder",
|
||||
lookup: "imageField:medialib",
|
||||
})
|
||||
```
|
||||
|
||||
`getCachedEntries()` expects `lookup` as the 8th argument and as a string, not as part of the `params` object.
|
||||
`getCachedEntries()` expects `lookup` as an option in the second arguments object.
|
||||
|
||||
Then consume the resolved entry from `_lookup`, for example `_lookup.imageField` or `_lookup.imageField?.[0]` depending on whether the schema stores one image or an array.
|
||||
|
||||
|
||||
Reference in New Issue
Block a user