Querying by DateTime in Ecto

泄露秘密 提交于 2019-12-08 17:20:44

问题


Here is what I have tried.

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

I also tried

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

Both return same message

value `%Ecto.DateTime{..}` in `where` cannot be cast to type :datetime in query

From what I understand I am supposed to be using Ecto.DateTime in my queries. Maybe I am missing something obvious? Thanks!


回答1:


The :datetime type is a native type and works only with tuples. If you set your column type to Ecto.DateTime in your schema, it will be able to work with higher level types like the Ecto.DateTime struct.



来源:https://stackoverflow.com/questions/30245703/querying-by-datetime-in-ecto

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!