ex_admin icon indicating copy to clipboard operation
ex_admin copied to clipboard

Bug in model with same relationship

Open mapeveri opened this issue 7 years ago • 0 comments

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

mapeveri avatar Apr 14 '17 23:04 mapeveri