[英]How to generate the form for a Geo custom type in Phoenix
On my Elixir / Phoenix app I have an Address
model that has a location
field on it. 在我的Elixir / Phoenix应用程序上,我有一个Address
模型,上面有一个location
字段。
The field is a Geo.Geometry custom type from the Geo library, with the following structure: 该字段是Geo库中的Geo.Geometry自定义类型,具有以下结构:
%Geo.Point{coordinates: {30, -90}, srid: 4326}
I am looking for a way to generate a form for my Address
model that includes this location
, but I'm not sure what's the proper way to do this. 我正在寻找一种为我的Address
模型生成包含此location
的表单的方法,但我不确定这样做的正确方法是什么。
I was thinking about adding virtual fields to my Address
model, like lat
and lng
, use them in the form and then "translate" those fields into a %Geo.Point
in the Address.changeset
function. 我正在考虑向我的Address
模型添加虚拟字段,如lat
和lng
,在表单中使用它们,然后将这些字段“转换”为Address.changeset
函数中的%Geo.Point
。
Is that the right way to go, or is there a more straightforward solution? 这是正确的方法,还是有更简单的解决方案? And if so, how to do this in the changeset? 如果是这样,如何在变更集中执行此操作?
Many thanks. 非常感谢。
我建议的方法终于奏效了:将lat
和lng
虚拟字段添加到Address
模型,然后使用put_changes
在Address
changeset中设置my location
字段的值。
Should avoid polluting schema with UI requirements. 应避免使用UI要求污染模式。 I strongly recommend reading José Valim post explaining the schemaless queries. 我强烈建议您阅读JoséValim的帖子,解释无模式查询。
http://blog.plataformatec.com.br/2016/05/ectos-insert_all-and-schemaless-queries/ http://blog.plataformatec.com.br/2016/05/ectos-insert_all-and-schemaless-queries/
Hope it helps. 希望能帮助到你。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.