簡單的要求: a1 = where(MyModel, [x], is_nil(x.some_foreign_id)) |> Repo.one()
例外: ** (exit) an exception was raised:
** (Ecto.MultipleResultsError) expected at most one result but got 6 in q
我有一個現有的數據庫,並有一個唯一索引在表 ALTER TABLE ONLY users ADD CONSTRAINT unique_document_id UNIQUE (document_id);
我沒有在任何外生遷移和我想使用變更集插入新記錄。下面是從模型和代碼的代碼中插入 defmodule User do
use Ecto.Schema
schema "user
我有這樣的代碼: if Map.has_key?(dbShop, "id") && Map.has_key?(dbProduct, "id") do
case Api.Repo.insertProductShop(conn, dbShop.id, dbProduct.id) do
{:ok, productShop} ->
{:ok, productShop}