Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiple Schemas in one Phoenix Form #120

Open
Danwhy opened this issue Nov 23, 2018 · 0 comments
Open

Multiple Schemas in one Phoenix Form #120

Danwhy opened this issue Nov 23, 2018 · 0 comments

Comments

@Danwhy
Copy link
Member

Danwhy commented Nov 23, 2018

For club-soda we have a form where users can sign up and also add a venue to the site at the same time.

We have two separate schemas: User and Venue, and are using these to generate the inputs, with the attributes coming through to the controller in two separate maps: %{user: %{...}, venue: %{...}}.

This works, but the problem comes when there's a validation error in the form. For our normal forms with one schema, the data from the form is kept in the changeset, and so remains in the form when the page reloads, but for this form, we don't have a single changeset that contains both the venue and user data, so we either keep the venue data, the user data, or none.

Is there a way to use two changesets in one form?

It seems that the only way to go about this is to use nested changesets, whereby the Venue schema would belong to the User schema, or vice versa:

This does seem to make sense, as any data that is in one single form should be related, but is this the only way?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant