Ecto:自定义 binary_id
Ecto: Custom binary_id
我有一个 Ecto 模型,我想将其存储在数据库中,其中包含从 elixir 函数生成的自定义 binary_id。这可能吗?
我的 id 函数如下所示:
def gen_id
String.upcase to_string Enum.take_random('abcdefghjkmnpqrstuvwxyz123456789', 8)
end
我的架构如下所示:
schema "orders" do
belongs_to :type, Invoicer.Customer
@primary_key {:id, :binary_id, autogenerate: true}
field :order_details, :string
timestamps()
end
我有一个 Ecto 模型,我想将其存储在数据库中,其中包含从 elixir 函数生成的自定义 binary_id。这可能吗?
我的 id 函数如下所示:
def gen_id
String.upcase to_string Enum.take_random('abcdefghjkmnpqrstuvwxyz123456789', 8)
end
我的架构如下所示:
schema "orders" do
belongs_to :type, Invoicer.Customer
@primary_key {:id, :binary_id, autogenerate: true}
field :order_details, :string
timestamps()
end