waseigo
AEAsh Elixir
•Created by waseigo on 2/12/2023 in #support
How to Ash-idiomatically get all unique values of an attribute across all records?
App.Api.Item
is a resource with an attribute :name
.
How can I go from the set of all records of Item (App.Api.Item |> App.Api.read!()
) to a list of all unique values of the :name
attribute in the most idiomatic way?119 replies
AEAsh Elixir
•Created by waseigo on 2/12/2023 in #support
Nested aggregates
In my Product Data Management webapp I'm trying to build with Ash, I have the following resources with attributes and relatioships in
App.Api
that, combined, construct/define an Item
.
* Category
: has a :code
attribute
* Family
: belongs_to
a Category (and also has a :name
, etc.)
* Variant
: belongs_to
a Variant, has a :code
attribute
The idea is that an Item
belongs_to
a Category and a Variant, and has a calculated attribute (also called :code) resulting from concatenating the Category :code
and the Variant :code
.
This means that Item
's :code
calculation must "pull" Category's :code
through the Variant it belongs to, which belongs to a Family, which belongs to a Category.
Item
's calculated :code
uniquely identifies a record.
I have tried the following in a cascade,
In lib/app/resources/item.ex
:
In lib/app/resources/variant.ex
:
In lib/app/resources/family.ex
:
...hoping that App.Api.Item |> App.Api.read!
would return records on which I can App.Api.load!(:code)
.
Instead:
What is the Ash-idiomatic way of achieving the goal of being able to access Item
's :code
?43 replies
AEAsh Elixir
•Created by waseigo on 2/12/2023 in #support
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? 😵💫38 replies
AEAsh Elixir
•Created by waseigo on 2/10/2023 in #support
Example of setting a has_one relationship
I would appreciate an example of setting up a has_one relationship.
I have the following resources:
Each resource has an attribute
uuid_primary_key :id
.
I want to establish a 1:1 relationship between the two resources.
So, I add the following to App.Api.Item
:
I get the following errors/warnings:
Do I need to define an attribute :item_id
in resource App.Api.Variant
? If so, what type would it be?
Or am I on the wrong path?10 replies
AEAsh Elixir
•Created by waseigo on 2/10/2023 in #support
Can a calculation use attributes of a related resource?
E.g., I have
belongs_to :brand, App.Portfolio.Brand
and
calculate :tagline, :string, expr(brand.name <> " — " <> name)
The result:
34 replies
AEAsh Elixir
•Created by waseigo on 2/9/2023 in #support
Example of :create action with simultaneous assignment of relationship
Perhaps I'm too influenced by Django, but I've been trying to :create a new instance of a resource that
belongs_to
two other resource types by passing the other resources' .id
values as parameters in the map, to no avail.
Following the Getting Started guide, I understand how I first create the Ticket resource instance and a Representative resource instance and then use the :assign
update action to assign the ticket to the representative.
However, how would I go about creating a ticket with the representative already being assigned during the :create
action?
If this is possible, what would it look like if I were to create a ticket with more than one related resources at once?
Or do I first need to create, then update/assign?9 replies
AEAsh Elixir
•Created by waseigo on 2/8/2023 in #support
"No changes detected, so no migrations or snapshots have been created."
Hi all. I am learning how to build a simple CRUD app with Ash, and for some reason
mix ash_postgres.generate_migrations
fails to pick up any migrations, even after I mix ash_postgres.drop
and rm -f priv/repo/migrations/*
to start from scratch.
Any clues as to why?21 replies