sezaru
Suggestion: Add possibility to write calculate expression inside code block
Currently, when writing a calculation, the third argument is the expression.
For example:
calculate :full_name, :string, expr(first_name <> " " <> last_name)
This looks clean and simple, but when the calculation is a little bit more complex, it starts to get a little bit messy:
calculate :total_feedbacks_in_class_this_month,
:integer,
expr(
count(feedbacks,
query: [
filter:
expr(
class_id == ^arg(:class_id) and
inserted_at >= fragment("date_trunc('month', now())") and
inserted_at <
fragment("date_trunc('month', now()) + interval '1 month'")
)
]
)
) do
argument :class_id, :string, allow_nil?: false
end
I was wondering if we could add an alternative way to write the calculations where we can not write the third argument and alternatively add it inside the calculate code block.
Something like this:
calculate :total_feedbacks_in_class_this_month, :integer do
expression expr(
count(feedbacks,
query: [
filter:
expr(
class_id == ^arg(:class_id) and
inserted_at >= fragment("date_trunc('month', now())") and
inserted_at < fragment("date_trunc('month', now()) + interval '1 month'")
)
]
)
)
argument :class_id, :string, allow_nil?: false
end
At least for me, this seems easier to read.
Marked As Solved
zachdaniel
Creator of Ash
You can do this today:
calculate :total_feedbacks_in_class_this_month, :integer do
calculation expr(
count(feedbacks,
query: [
filter:
expr(
class_id == ^arg(:class_id) and
inserted_at >= fragment("date_trunc('month', now())") and
inserted_at < fragment("date_trunc('month', now()) + interval '1 month'")
)
]
)
)
argument :class_id, :string, allow_nil?: false
end
0
Last Post!
zachdaniel
Creator of Ash
Popular in Questions
Hi guys, i’m new in the Elixir world, and i have to say, that i love it!
i’m having some problem to understand anonymous functions with ...
New
What is the difference between System.get_env and Application.get_env? For example, what are best practices to use one versus another.
New
I have a another noob question about loop. Since elixir is immutable, while loop is not directly possible.
total = 10
while total != 0
...
New
Hi All,
I set a environment variables in dev.exs , like below code.
when i start server, how can i set the ${enable} value?
thanks.
d...
New
Good day to you all.
I have been struggling to get a query involving like and ilike to work.
Can anyone assist me on this, please?
pro...
New
I am trying to start a new phoenix project with elixir 1.9, but mix phx.new does not work. It says that ** (Mix) The task "phx.new" could...
New
Hi!
Currently I want to submit a form by pressing the Enter key. However, since my input field is of type “textarea” this is just adds a...
New
Other popular topics
Hello, can anybody help here..? I have a list of players and I what to delete an element, but every for loop the list is reverting to ori...
New
I would like to know what is the best IDE for elixir development?
New
I want to highlight html closing tags when i click a html tag. That works in .html files but doesnt work for html.eex templates. How can...
New
This post is a wiki (feel free to hit the edit button near the bottom right of this post to add your own changes!)
This post collects co...
New
i’m a new one to elixir
which editor can i use
vs code? or atom?
Thanks! :smiley:
New
In the code below, if the create action is not set to accept “extra_key” as an input, it errors out with a message shown above. Is there ...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #supervisor
- #elixirconf-us
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #metaprogramming
- #security
- #hex









