ex_admin
ex_admin copied to clipboard
Bug in model with same relationship
Hi, i have this model:
defmodule App.Category do
use App.Web, :model
schema "categories" do
field :name, :string
field :description, :string
field :slug, :string
belongs_to :parent, App.Category
has_many :categories, App.Category, foreign_key: :parent_id
timestamps()
end
@doc """
Builds a changeset based on the `struct` and `params`.
"""
def changeset(struct, params \\ %{}) do
struct
|> cast(params, [:name, :description, :slug])
|> validate_required([:name, :description, :slug])
end
end
And when I save the record it does not save me the value of the combobox of parent_id. However, if it works for me when I insert a record from the console.
category = %App.Category{name: "Backend", description: "Backend category", slug: "backend", parent_id: 2}
App.Repo.insert category