Hey friends! A long time quality of life feature we’ve been wanting to add is the ability to refer to to-one relationships in calculations. Since an example is worth a thousand words, lets see how you would have had to refer to to-one
related information in a calculation before:
The old way
Using a named aggregate
aggregates do
# add a `first` aggregate
first :authors_first_name, :authors, :first_name
end
calculations do
# refer to that in a calculation
calculate :some_calculation, :string, expr(authors_first_name ...)
end
Using in-line aggregates
# use an in-line first aggregate
calculate :some_calculation, :string, expr(first(author, field: :first_name))
The new way
The old ways will continue to work, but you can now use to-one
path relationships directly in your calculations. You can’t use to-many
relationships in a calculation, i.e posts.text
in a calculation, because which post are you referring to?
calculate :some_calculation, :string, expr(author.first_name ...)
Hopefully this will make writing certain kinds of calculations much simpler