How to use relationship id in a `get_by` read action

My resource has this relationship:
belongs_to :customer, Customer do
allow_nil? true
attribute_writable? true
end
belongs_to :customer, Customer do
allow_nil? true
attribute_writable? true
end
This means that this resource table will contain a :customer_id field. Now I want to create a read action that will filter it by the :customer_id. I can do that by passing that as an argument and doing the filter manually, but I expected that I could use the get_by shortcut here, like this:
read :get_by_customer_id do
get_by :customer_id
end
read :get_by_customer_id do
get_by :customer_id
end
The problem is that this fails with Ash saying that there is not attribute, calculation or aggregate with that name.
2 Replies
ZachDaniel
ZachDaniel2y ago
That may be a bug in that validator Can you open an issue on ash? In the meantime, make it get? true and add the argument/filter yourself should do it
Blibs
BlibsOP2y ago
GitHub
bug: read action get_by don't recognize relationship attributes · I...
Describe the bug If you have a relationship in your resource, for example with belongs_to, get_by shortcut for a read action will not find the correspondent relationship id attribute. To Reproduce ...

Did you find this page helpful?