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
ZachDaniel
ZachDaniel4mo ago
You can provide a starting query for the load load(related: Ash.Query.for_read(...)
Vinicius Moreira
Vinicius MoreiraOP4mo ago
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

Did you find this page helpful?