directus / directus/rstore

updateForm : improve relations support

Open
#34 3 comments 0 reactions 0 assignees View on GitHub
rstore
Dominant language
TypeScript
Stars
449
Forks
21
Avg merge
6d 22h
Merged PRs (30d)
2

Description

### Clear and concise description of the problem

Considering the following scenario :

```ts
export interface Vehicle {
id: number
name: string
}

export interface Itinerary {
id: number
vehicle: Vehicle
label: string
}
```

```ts
const updateFormSchema = z.object({
vehicle: z.number(),
label: z.string()
})

export default defineItemType().model({
name: 'itineraries',
formSchema: {
update: updateFormSchema
}
})
```

when I want to create an updateSchema :
```ts
const itineraryForm = await store.itineraries.updateForm(props.id)
```

`itineraryForm.vehicle` is an objet of type Vehicle. But in my case I would like to have his `id`.
I have try with pass `defaultValues` to overrides this, but it don't work.

### Suggested solution

We can imagine to pass the data to the defaultValues function to map model within the form

```ts
const itineraryForm = await store.itineraries.updateForm(props.id, {
defaultValues: (item) => ({
...item,
vehicle: item.vehicle.id
}
})
```

### Alternative

_No response_

### Additional context

_No response_

### Validations

- [x] Follow our [Code of Conduct](https://github.com/Akryum/rstore/blob/main/CODE_OF_CONDUCT.md)
- [x] Read the [Contributing Guidelines](https://github.com/Akryum/rstore/blob/main/CONTRIBUTING.md).
- [x] Read the [docs](https://rstore.starpad.dev/guide/).
- [x] Check that there isn't [already an issue](https://github.com/Akryum/rstore/issues) that requests the same feature to avoid creating a duplicate.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.