andreas_ementio
Extensions like AshArchival in a Base Resource
I have a base resource which is use by almost all of the resources in the project, the base resource contains extensions like AshPostgres and AshArchival which seems to work just fine.
Now i am trying to add a base filter for AshArchival.
Since i have never done anything with marcos i am a bit confused on how to approach this.
The base resource looks like this:
defmodule App.BaseResource do
# ...
defmacro __using__(opts) do
opts =
opts
|> Keyword.merge(
[extensions: [AshPaperTrail.Resource, AshArchival.Resource]],
fn _key, extensions, base_extensions ->
Enum.uniq(extensions ++ base_extensions)
end
)
|> Keyword.put(:data_layer, AshPostgres.DataLayer)
quote do
use Ash.Resource, unquote(opts)
paper_trail do
change_tracking_mode :changes_only
belongs_to_actor :user, App.Accounts.User, domain: App.Accounts
store_action_name? true
end
attributes do
create_timestamp :inserted_at
update_timestamp :updated_at
end
#
# resource do
# base_filter expr(is_nil(archived_at)) # <-- archived_at is an undefined variable
# end
# actions do
# read :archived do
# filter expr(not is_nil(archived_at)) # <--
# end
postgres do
table App.BaseResource.tablename(__MODULE__)
repo App.Repo
base_filter_sql "archived_at IS NULL"
end
end
end
end
Marked As Solved
zachdaniel
Creator of Ash
Use a fragment instead, where you won’t have macro nesting issues.
use Ash.Resource, unquote(Keyword.put(opts, :fragments, App.BaseResource.Archival))
defmodule MyApp.BaseResource.Archival do
use Spark.Dsl.Fragment, of: [Ash.Resource], extensions: [AshArchival]
...put all your archival config here, in addition to the base filter.
end
0
Popular in Questions
What is the idiomatic way of matching for not nil in Elixir?
E.g.,
First way:
defp halt_if_not_signed_in(conn, signed_in_account) when...
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
After calling mix ecto.create I get this error:
17:00:32.162 [error] GenServer #PID<0.412.0> terminating
** (Postgrex.Error) FATAL...
New
Hello, how can I check the Phoenix version ?
Thanks !
New
I am trying to figure out how Mix knows whether the environment is test, dev, or prod – where is this set?
Thanks.
New
Hey all,
I discovered Elixir and I love it. I always wanted to learn a functional programming and I intended to go for Haskell, but afte...
New
I’m not a pro in using Regex and can’t figure out why the following behaviour happens, especially if we take into account the difference ...
New
I am using Ecto timestamps with postgres, I can see the timestamps() use the :naive_dateime but for my use case I wanted to store the ti...
New
I am trying to run a deploy with docker and I successfully runned with this command:
docker build -t romenigld/blog-prod .
but when I t...
New
Hello!
Sorry for this astonishing simple question, but I’m really stuck. I try to set up the intellij-elixir plugin, but I don’t know ho...
New
Other popular topics
I am constructing a JSON object (map) and I need to conditionally set a field. I’m trying to write proper elixir-way code… and I’m at a l...
New
Hello all!
I am typing this post from my new MacBook Pro with the M1 chip. I’m loving it so far, and will probably use it as my daily dr...
New
To my knowledge, put_in, Map.update etc. all have the one limitation of not automatically creating intermediate keys when needed (for exa...
New
Anybody knows a comprehensive comparison of Django and Phoenix, thanks for the help.
Where are they similar?
Where do they differ the m...
New
Surface is an experimental library built on top of Phoenix LiveView and its new LiveComponent API that aims to provide a more declarative...
New
In templates/appointment/index.html.eex:
<%= for appointment <- @appointments do %>
<tr>
<td><%= appoi...
New
Please see the new poll here: Which code editor or IDE do you use? (Poll) (2022 Edition)
It’s been a while since we first asked this, I...
New
Hi there,
I am working with Ecto-Postgresql and I need to call all of the records from a specific table but the table has 40,000 records...
New
Seen any cool LiveView demos, sample apps or examples? Please post them here! :003:
New
I wrote this comment on r/haskell, and it’s not popular there. :wink: But I think I’m on to something…
Haskell reminds me of Java, and e...
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









