Module Calculations: Concat example leads to Enum.map_join/3 error (separator argument missing)
I have the following 3 resources:
Family
belongs_to
a Brand
and a Category
.
Brand
and Category
each have a :name
string attribute.
Within Family
I have two aggregates:
...and one calculation for :tagline
that should concatenate the two aggregates above.
The Concat
code is in lib/api/calculations.ex
.
I have a record f
of type App.Api.Family
, associated with a Brand
and a Category
record.
In IEx:
Alternatively:
What am I doing wrong? šµāš«21 Replies
@Zach Daniel, any ideas?
Sorry, forgot to come back to this
š¤
lemme take a look at the builtin calculation
fixed in
main
Do you mean it was a bug that is now fixed in the trunk?
Yeah I just pushed a fix
aha, thank you!
You can use main, or you can make the dependencies explicit via:
I looked at github and saw that the fix is for
lib/ash/resource/calculation/concat.ex
-- does this mean that Ash already provides the Concat module, and that my lib/api/calculations.ex
is not required?I guess it does, huh? https://github.com/ash-project/ash/blob/main/lib/ash/resource/calculation/builtins.ex
GitHub
ash/builtins.ex at main Ā· ash-project/ash
A declarative and extensible framework for building Elixir applications. - ash/builtins.ex at main Ā· ash-project/ash
oh
I thought you were using it š
I guess my
calculations.ex
was never loaded because anyway I never imported it
No, I just copied the Concat module from the Getting Started guideOhhh okay
well I should fix that too then
But yes, we do have a built in
concat
that I just fixed
Just pushed up a fix for that guide, the docs will be fixed on the next releasethx!
Indeed, I just saw that actually I was using the guide's Concat
In your custom
concat
you can add def load/3
and return the fields required
if you'd rather do that than use ash's main branch, your call šI'm trying this out.
My
calculations.ex
file contains defmodule Concat ...
from the latest commit https://github.com/ash-project/ash/commit/2c8b07fd0b9a7b3b0bb8a5886f1255c6ef91ba33 (so it now includes the load/3
part).
My resource contains a calculation:
In IEx (where f
is a record of type App.Api.Family
:
oh š¤
I think your separator is nil actually
I thought this was allowed due to
allow_empty?: true
allow_empty?
prevents the type from turning ""
into nil
but if no separator is supplied, it will be nil
Ah so I should always pass a separator?
Or set
default: ""
on the separator argument
and allow_nil?: false
is probably what you want
I'll update the exampleExcellent, works now! š„³
š„³