为主键和验证生成自定义编号

时间:2016-12-05 14:56:27

标签: elixir ecto

我有以下架构:

  @primary_key false
  schema "companies" do
    field :number,         :integer, primary_key: true
    field :name,           :string
    field :street,         :string
    field :zipcode,        :integer
    field :location,       :string
    field :phone,          :integer
    field :company_class,  :string
    field :country_iso,    :string
    field :email,          :string
    field :password,       :string, virtual: true
    field :password_hash,  :string
    has_many :contacts,    Busiket.Contact, on_delete: :delete_all

    timestamps
  end

  def register(struct, params \\ %{}) do

  end

如果通过寄存器功能创建变更集,如何为字段number生成数字?

如果数字已经可用,我如何首先验证数据库,以避免重复。

0 个答案:

没有答案