I have a subscription like this.
defmodule Rebirth.Subscription do
use Rebirth.Web, :model
schema "subscriptions" do
...
belongs_to :user, Rebirth.User
...
end
...
def update_user(model, params \\ :empty) do
model
|> cast(params, @required_fields, @optional_fields)
|> cast_assoc(:user, required: false)
end
end
I want to associate a user to the subscription
So I tried
Rebirth.Subscription.update_user(subscription, %{user_id: 1})
or
Rebirth.Subscription.update_user(subscription, %{user: user})
When I run it I get the following error:
** (ArgumentError) unknown assoc `user` in `cast_assoc`
How do I update the user_id?
Thanks!