我试图寻找那些没有在他们的User
领域的某些字符串元素的所有match_history
s。我花了猜测与此:
matched_user = User |> where([u], ^device_id not in u.match_history) |> limit(1) |> VideoChat.Repo.one
但似乎在not
部分断裂。有没有办法做到这一点?
尝试
User |> where([u], not ^device_id in u.match_history)
对于那些谁正在寻找一个“阵列不包含任何”行为。 例如,“match_history不含DEVICE_1设备_2,device_3”
鉴于你使用PostgreSQL,可以使用一个片段与array contains @>
operator。
from t in queryable, where: not fragment("? @> ?::varchar[]", t.match_history, ^device_ids)
要么
from t in queryable, where: fragment("NOT ? @> ?::varchar[]", t.match_history, ^device_ids)