Last active
October 5, 2016 09:08
-
-
Save coryodaniel/dcf637ec14da7cbdec568ee79f03c95d to your computer and use it in GitHub Desktop.
Elixir Ecto cast_assoc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule User do | |
def changeset(user, params) do | |
user | |
|> cast(params, @allowed_params) | |
|> validate_required(@required_params) | |
# Account.changeset is inferred by default | |
|> cast_assoc(:account, required: true, with: &Account.registration_changeset/2) | |
end | |
end | |
account = %{plan: "free"} | |
user = %{email: "coolio@example.com", password: "bananas", account: account} | |
User.changeset(%User{}, user) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment