Phoenix How create association in Api Rest

Hi Masters, I’m new in Elixir and Phoenix, my question is How to insert data between two associated schemes, but only insert in one. What is my wrong?

Schema Customer:

defmodule App.Customers.Customer do
use Ecto.Schema
import Ecto.Changeset

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)
end
end

Schema Contact:

defmodule App.Customers.Contact do
use Ecto.Schema
import Ecto.Changeset

schema “contacts” do
field :number, :integer
belongs_to :customers, App.Customers.Customer

timestamps()

end

@doc false
def changeset(contact, attrs \ %{}) do
contact
|> cast(attrs, [:number])
|> validate_required([:number])
end
end

Context:

def create_customer(attrs \ %{}) do
%Customer{}
|> Customer.changeset(attrs)
|> Ecto.Changeset.cast_assoc(:contacts, with: &Contact.changeset/2)
|> Repo.insert()
end

Customer Controller:

defmodule AppWeb.CustomerController do
use AppWeb, :controller

alias App.Customers
alias App.Customers.Customer

action_fallback AppWeb.FallbackController

def index(conn, _params) do
customers = Customers.list_customers()
render(conn, “index.json”, customers: customers)
end

def create(conn, customer_params) do
with {:ok, %Customer{} = customer} <- Customers.create_customer(customer_params) do
conn

  |> put_status(:created)
  |> put_resp_header("location", Routes.customer_path(conn, :show, customer))
  |> render("show.json", customer: customer)
end

end