Use arguments in Relationship
I would like to pass some arguments to a has_many relationship, which would be provided by a read action.
actions do
read :list do
argument :start_in, DateTimeUsec, allow_nil?: false
argument :finish_id, DateTimeUsec, allow_nil?: false
prepare build(load: :transactions)
pagination keyset?: true, default_limit: 5, countable: :by_default
end
end
relationships do
has_many :transcations, Transactions
end
2 Replies
You can provide a starting query for the load
load(related: Ash.Query.for_read(...)
load(transcations: Transactions.filter_dates(^start_in, ^finish_id))
defmodule Clients ....
relationships do has_many :transcations, Transactions end
actions do read :list do argument :start_in, DateTimeUsec, allow_nil?: false argument :finish_id, DateTimeUsec, allow_nil?: false prepare build(load: [transcations: Transactions.filter_dates(^start_in, ^finish_id)]) pagination keyset?: true, default_limit: 5, countable: :by_default end end end