help with ash_geo for using locations.

Resource definition looks like
defmodule CompaniesRegEx.Resources.Recruiters do
use Ash.Resource, data_layer: AshPostgres.DataLayer
import AshGeo.Postgis


actions do
defaults [:create, :read, :update, :destroy]

action :create_loc do
argument :location, :geo_any

change set_attribute(:location, arg(:location))
end

read :containing do
argument :location, :geo_any do
allow_nil? false
constraints geo_types: :point
end

filter expr(^st_within(^arg(:location), location))
end
end


attributes do
# Add an autogenerated UUID primary key called `:id`.
uuid_primary_key :id
attribute :location, :geometry
end

end
defmodule CompaniesRegEx.Resources.Recruiters do
use Ash.Resource, data_layer: AshPostgres.DataLayer
import AshGeo.Postgis


actions do
defaults [:create, :read, :update, :destroy]

action :create_loc do
argument :location, :geo_any

change set_attribute(:location, arg(:location))
end

read :containing do
argument :location, :geo_any do
allow_nil? false
constraints geo_types: :point
end

filter expr(^st_within(^arg(:location), location))
end
end


attributes do
# Add an autogenerated UUID primary key called `:id`.
uuid_primary_key :id
attribute :location, :geometry
end

end
The error seems to be
Compiling 2 files (.ex)

== Compilation error in file lib/companies_reg_ex/resources/recruiters.ex ==
** (CompileError) lib/companies_reg_ex/resources/recruiters.ex:34: undefined function change/1 (there is no such import)
(ash 2.13.2) expanding macro: Ash.Resource.Dsl.Actions.Action.action/2
Compiling 2 files (.ex)

== Compilation error in file lib/companies_reg_ex/resources/recruiters.ex ==
** (CompileError) lib/companies_reg_ex/resources/recruiters.ex:34: undefined function change/1 (there is no such import)
(ash 2.13.2) expanding macro: Ash.Resource.Dsl.Actions.Action.action/2
when I add import Ash.Expr above, I get
(CompileError) lib/companies_reg_ex/resources/recruiters.ex:29: function expr/1 imported from both Ash.Filter.TemplateHelpers and Ash.Expr, call is ambiguous
(CompileError) lib/companies_reg_ex/resources/recruiters.ex:29: function expr/1 imported from both Ash.Filter.TemplateHelpers and Ash.Expr, call is ambiguous
10 Replies
abeeshake456
abeeshake456OP2y ago
@\ ឵឵឵ : I believe ash_geo is by you? import AshGeo.Expr was suggested in docs for ash_geo but that fails to compile with error
** (CompileError) lib/companies_reg_ex/resources/recruiters.ex:6: module AshGeo.Expr is not loaded and could not be found
** (CompileError) lib/companies_reg_ex/resources/recruiters.ex:6: module AshGeo.Expr is not loaded and could not be found
barnabasj
barnabasj2y ago
action :create_loc do
argument :location, :geo_any

change set_attribute(:location, arg(:location))
end
action :create_loc do
argument :location, :geo_any

change set_attribute(:location, arg(:location))
end
Maybe it should be create not action
create :create_loc do
argument :location, :geo_any

change set_attribute(:location, arg(:location))
end
create :create_loc do
argument :location, :geo_any

change set_attribute(:location, arg(:location))
end
action is for basic stuff that does not explicitly work with the resource, therefore change might not be possible there
abeeshake456
abeeshake456OP2y ago
docs for action say
The :action type is a special type of action that can do essentially whatever you want.
The :action type is a special type of action that can do essentially whatever you want.
barnabasj
barnabasj2y ago
I think this is more in the line of manual actions something that is not a typical create/update/delete
barnabasj
barnabasj2y ago
Ash HQ
Ash.Resource
View the documentation for Ash.Resource on Ash HQ.
barnabasj
barnabasj2y ago
there is no change in the dsl for action
abeeshake456
abeeshake456OP2y ago
that helps! 🙂 it works! Thankks @barnabasj ! how do I mark it solved? :p
barnabasj
barnabasj2y ago
good question xD
abeeshake456
abeeshake456OP2y ago
at the very very top, there is edit tags -> add Solved!
\ ឵឵឵
\ ឵឵឵2y ago
Hi @abeeshake456, thanks for the report. I've updated the readme to correctly reflect the new module naming and use create, as well as some updates for latest ash and ash_postgres. v0.1.3 will be up in a few minutes after CI.

Did you find this page helpful?