elixir - 在Ecto中按DateTime查询

标签 elixir phoenix-framework ecto

这是我尝试过的。

date = Ecto.DateTime.from_erl(:calendar.universal_time())
query |> where([record], record.deadline >= ^date)

我也试过了
date = Ecto.DateTime.from_erl(:calendar.universal_time())
query = from m in MyApp.SomeModel,
      where: m.deadline >= ^date,
      select: m

两者都返回相同的消息
value `%Ecto.DateTime{..}` in `where` cannot be cast to type :datetime in query

据我了解,我应该在查询中使用Ecto.DateTime。也许我缺少明显的东西?谢谢!

最佳答案

:datetime类型是 native 类型,仅适用于元组。如果您在架构中将列类型设置为Ecto.DateTime,它将能够使用更高级别的类型,例如Ecto.DateTime结构。

关于elixir - 在Ecto中按DateTime查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30245703/

相关文章:

elixir - 如何使用Ecto.Repo的预加载功能并实现软删除

elixir - 管理多对多关联

elixir - ectocast_assoc 查找或创建

elixir - Ecto assoc_constraint 不起作用

elixir - 使用字符串查询仓库

elixir - 如何建立和插入多对多关联

postgresql - 如何使用 ecto 更新或插入多行? (更新插入)

sorting - 根据 map 中的值对 map 列表进行排序

enums - 枚举频率 - 错误 UndefinedFunctionError

elixir - Phoenix 框架 : mix test fails with argumenterror on new app