I want to POST for association one to many with JSON in Phoenix Elixir.
My controller:
def create(conn, %{“customer” => customer_params}) do
with {:ok, %Customer{} = customer} <- Customers.create_customer(customer_params) do
My Schema:
schema "customers" do
field :email, :string
field :name, :string
has_many :contacts, App.Customers.Contact
timestamps()
end
@doc false
def changeset(customer, attrs \\ %{}) do
customer
|> cast(attrs, [:name, :email])
|> validate_required([:name, :email])
|> unique_constraint(:email)
|> cast_assoc(:contacts, with: &App.Customers.Contact.changeset/2)
end
The problems is:
# no function clause matching in AppWeb.CustomerController.create/2
1
%Plug.Conn{adapter: {Plug.Cowboy.Conn, :...}, assigns: %{}, before_send