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