camstuart
How to derive a value inside an action, so the changeset is enriched?
Hello,
Say I have a cut down version of my create action.
I would like to populate an attribute (:geom) by using accepted values (:latitude, :longitude)
attributes do
attribute :latitude, :float, allow_nil?: false
attribute :longitude, :float, allow_nil?: false
attribute :geom, :geometry, allow_nil?: false
end
actions do
defaults [:read]
create :create do
accept [:latitude, :longitude]
# I should be able to build a geometry 'point' field like so:
# "POINT(#{:longitude} #{:latitude})"
# but how to apply :geom to the changeset?
end
end
Can someone please describe the “Ash” way of doing this?
I have a few use case like this, even triggering an oban job to go off and get data from an external to enrich related fields
Thanks.
Most Liked
camstuart
Thanks @barnabasJ !
You have put me on the right track. Turns out the creation of the geometry types was easier like so:
create :create do
accept [:latitude, :longitude]
change fn changeset, _ ->
Ash.Changeset.change_attribute(
changeset,
:geom,
%Geo.Point{
coordinates:
{Ash.Changeset.get_attribute(changeset, :latitude),
Ash.Changeset.get_attribute(changeset, :longitude)},
srid: 4326
}
)
end
end
Although I believe AshGeo has it’s own DSL for coercing the postgis type, I found it easier to use the underlying library in this case.
But now I know how to intercept a changeset!
Thanks again
3
Popular in Discussions
A big advantage to Elixir is all the distributed goodness but for many applications running on multiple nodes having integrated Etcd, Zoo...
New
Background
A few days ago I was listening to The future of Elixir from Elixir Talks, with Dave Thomas (@pragdave ) and Brian Mitchell.
I...
New
After doing a port from a c++ library to my project in phoenix I’ve seen that I need a faster way to run this algorithm and I found this ...
New
On reading dhh’s latest The One Person Framework it strikes me that Phoenix with LiveView is already pretty much this. However, never hav...
New
The reason that Rails is as popular as it is is because it’s very easy for relatively inexperienced developers to get a lot of work done....
New
Please, let me know if this kind of discussion already took place in another topic
.
Hi all, how do you consider if is better to build ...
New
Hi all,
In the last days, two things happened:
A blog post titled “They might never tell you it’s broken” made the rounds. It’s about ...
New
In general I’ve been sticking to this community style guide GitHub - christopheradams/elixir_style_guide: A community driven style guide ...
New
I’m looking for a host for the server part of a small (personal) side project that I’m working on. It’s currently written in Node.js and ...
New
We’re considering our architecture from a viewpoint of scaling our traffic heavily over the next 6 months. Our current deployment is runn...
New
Other popular topics
This post is an instruction guide to help you setup your Neovim for Elixir development from scratch. It includes general information on h...
New
Hi,
I am new to Elixir. I am trying to use the DateTime component to insert a date into MySQL however the there seems to be no way to fo...
New
I am trying to figure out how Mix knows whether the environment is test, dev, or prod – where is this set?
Thanks.
New
Hi everyone,
One of the features added to Elixir early on to help integration with Erlang code was the idea of overridable function defi...
New
In templates/appointment/index.html.eex:
<%= for appointment <- @appointments do %>
<tr>
<td><%= appoi...
New
I want to highlight html closing tags when i click a html tag. That works in .html files but doesnt work for html.eex templates. How can...
New
I’ve read in another post that it may be possible with a router helper - but I couldn’t find an appropriate one, and tbh, I’m still just ...
New
Original source of discussion: This topic on the Pragmatic Programmers’ Functional Web Development with Elixir, OTP, and Phoenix forum.
...
New
Currently suffering from paralysis by [HTTP client] analysis. This is rather unusual in Elixirland as there tends to be consensus on the ...
New
Update:
How to use the Blogs & Podcasts section
You can post links to your blog posts or podcasts either in one of the Official Blog...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #supervisor
- #advent-of-code
- #elixirconf-us
- #distillery
- #processes
- #forms
- #api
- #metaprogramming
- #security
- #performance









