How to use Geo library to create valid Ecto Model changeset?

主宰稳场 提交于 2019-12-05 05:54:42

According to the tests for the library:

https://github.com/bryanjos/geo/blob/351ee6c4f8ed24541c9c2908f615e7b0a238f010/test/geo/ecto_test.exs#L100

You need to pass a Geo.Point to your changeset function:

changeset = Place.changeset(%Place{}, %{coordinates: %Geo.Point{coordinates: {49.44, 17.87}})

You can read more about custom ecto types in [the docs].(https://hexdocs.pm/ecto/Ecto.Type.html#content)

For future reader, there is also geo_postgis, by the same author and based on geo, which is a postgrex extension and works with ecto.

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