How not to select fields when loading a resource

Is there a way in Ash to not select a field when loading a resource? We have some fields in the DB that are really large and we don't need to select them most of the time. Is there a way to tell Ash not to select that field for this particular load or action?
5 Replies
barnabasj
barnabasj2y ago
https://ash-hq.org/docs/module/ash/latest/ash-query#function-select-3
Resource
|> Ash.Query.for_read(:read, opts)
|> Ash.Query.select([:fields, :you, :want, :to_select])
|> Api.read!()
Resource
|> Ash.Query.for_read(:read, opts)
|> Ash.Query.select([:fields, :you, :want, :to_select])
|> Api.read!()
Ash HQ
Module: Ash.Query
View the documentation for Ash.Query on Ash HQ.
barnabasj
barnabasj2y ago
or https://ash-hq.org/docs/module/ash/latest/ash-query#function-deselect-2
Resource
|> Ash.Query.for_read(:read, opts)
|> Ash.Query.deselect([:fields, :you, :do, :not, :want, :to_select])
|> Api.read!()
Resource
|> Ash.Query.for_read(:read, opts)
|> Ash.Query.deselect([:fields, :you, :do, :not, :want, :to_select])
|> Api.read!()
Ash HQ
Module: Ash.Query
View the documentation for Ash.Query on Ash HQ.
barnabasj
barnabasj2y ago
The same functions are available in the Ash.Changeset module. You could do this in the action itself with a prepare/build step I think
rohan
rohanOP2y ago
Got it, thank you!
skander
skander2y ago
TIL about deselect!

Did you find this page helpful?