作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试将 Ecto Repo.get_by 与多个子句一起使用,但在查找语法示例时遇到了麻烦。我需要查询数据库中的其中一个或 2 个字段匹配的位置,因此子句之间有一个“或”条件。我不知道这是否可能。
Repo.get_by(User, [username: username, email: username], prefix: :accounts)
最佳答案
Repo.get_by
不允许 OR
中的条款。您需要使用 from
编写完整的查询。 ,或 where
的组合和 or_where
,然后通过管道连接到 Repo.one
:
from(u in User, where: u.username == ^username or u.email == ^username)
|> Repo.one
User
|> where(username: ^username)
|> or_where(email: ^username)
|> Repo.one
关于elixir - 带有多个 'or' 子句的 Ecto Repo.get_by,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52114528/
我正在尝试将 Ecto Repo.get_by 与多个子句一起使用,但在查找语法示例时遇到了麻烦。我需要查询数据库中的其中一个或 2 个字段匹配的位置,因此子句之间有一个“或”条件。我不知道这是否可能
我是一名优秀的程序员,十分优秀!