Stefan Wintermeyer
AEAsh Elixir
•Created by Stefan Wintermeyer on 9/24/2023 in #support
add_tag but unique
A product has a many_to_many relationship to a tag (via a product_tag resource).
lib/app/shop/resources/product.ex This works nicely: Unfortunately I can also add another "Yellow" tag via an update: Obviously this should not happen. The "Yellow" tag should be unique. The longer I think about this the lesser I know how to solve it. Should I through a validation error? How can I do this? Should I just OK it but not adding another tag? How would I do that?
lib/app/shop/resources/product.ex This works nicely: Unfortunately I can also add another "Yellow" tag via an update: Obviously this should not happen. The "Yellow" tag should be unique. The longer I think about this the lesser I know how to solve it. Should I through a validation error? How can I do this? Should I just OK it but not adding another tag? How would I do that?
14 replies
AEAsh Elixir
•Created by Stefan Wintermeyer on 9/24/2023 in #support
How to add_tag? Managing Relationships
I try to adapt https://ash-hq.org/docs/guides/ash/latest/topics/managing-relationships for an application where a
product
which has a many_to_many
relationship to tags
.
lib/app/shop/resources/product.ex
I get this error:
How can I fix that?6 replies
AEAsh Elixir
•Created by Stefan Wintermeyer on 9/23/2023 in #support
many_to_many update problem
I have a
product
which has many_to_many tags
. Creating works. Updating doesn't. Here's the resource code:
lib/app/shop/resources/product.ex
Here's what I do in the iex:
That all works nicely. But I can not update the products tags or the even the product:
How can I fix this?13 replies
AEAsh Elixir
•Created by Stefan Wintermeyer on 9/22/2023 in #showcase
Tutorial: has_many in 2m 19s
https://www.youtube.com/watch?v=jQZGHl4B4fU
Source code and other tutorials at https://elixir-phoenix-ash.com/ash/relationships.html#ash-has_many
1 replies
AEAsh Elixir
•Created by Stefan Wintermeyer on 9/21/2023 in #showcase
Tutorial: belongs_to in 2 minutes
I uploaded a video tutorial how to configure and use belongs_to.
https://www.youtube.com/watch?v=lP8YtkXD3RE
4 replies
AEAsh Elixir
•Created by Stefan Wintermeyer on 9/20/2023 in #support
How to create a product with many_to_many tags?
Setup:
The iex preparation:
Question: How can I create a new product which has the two tags
good_deal_tag
and yellow_tag
? Something like:
18 replies
AEAsh Elixir
•Created by Stefan Wintermeyer on 9/20/2023 in #support
How to autoload a relationship?
The setup:
lib/app/shop/resources/product.ex
I want to query for the product "Banana":
Question: How can I autoload the
category
when I query for a product
so that I don't have to do two SQL requests? App.Shop.Product.by_name("Banana")
should get me the product
and the category
.5 replies
AEAsh Elixir
•Created by Stefan Wintermeyer on 9/20/2023 in #support
How to create a product with a category id?
The setup:
lib/app/shop/resources/category.ex
lib/app/shop/resources/product.ex
Question: How can I create a new Product which includes a Category?
This is what I tried:
The
category_id
is nil
both times.15 replies
AEAsh Elixir
•Created by Stefan Wintermeyer on 9/19/2023 in #showcase
Ash Resource - 3 minute introduction
Learn how to setup an Ash resource with create, read, update and destroy.
https://www.youtube.com/watch?v=tYCL0Rk12no
3 replies
AEAsh Elixir
•Created by Stefan Wintermeyer on 9/14/2023 in #support
Validate not nil, min and max for a string
The following validation code doesn't work:
In the documentation I can only find examples for
allow_nil?
or constraints: [min_length: 1, max_length: 255]
but none where both are combined.
How do I have to change the code to work?5 replies
AEAsh Elixir
•Created by Stefan Wintermeyer on 9/11/2023 in #support
Using code_interface args
When I use
I have access to
Office.ToDoList.Task.create!("test")
but not to Office.ToDoList.Task.create!(%{subject: "test2"})
. For the later one to work I have to use define :create
but then the first version doesn't work.
Is there a way to have access to both versions or would that be a misuse of the code_interface concept?13 replies
AEAsh Elixir
•Created by Stefan Wintermeyer on 2/13/2023 in #support
Many To Many Relationship Example
After reading https://www.ash-hq.org/docs/guides/ash/latest/topics/relationships.md#has-many and https://ash-hq.org/docs/dsl/ash/latest/ash-resource-dsl/relationships/many_to_many I am a little bit confused since the examples use different code. I am looking for a simple example which I can copy and paste. Something like a blog post which has multiple tags associated via a many to many relationship:
- What do I have to change in the existing files?
- How do I have to do the third resource?
- How would I add a tag to a blog post the Ash way?
5 replies
AEAsh Elixir
•Created by Stefan Wintermeyer on 2/12/2023 in #support
Can I fetch a resource with `get :id`?
To fetch a resource by a specific
id
I use this code:
Is there a shorter already build in way of fetching a single resource by it's id
?4 replies
AEAsh Elixir
•Created by Stefan Wintermeyer on 2/9/2023 in #support
Which type for Text?
How long can a
Ash.Type.String
become with AshPostgres.DataLayer
? 255 characters? What type would I use for longer texts? I found this list but didn't find a text
entry:
3 replies
AEAsh Elixir
•Created by Stefan Wintermeyer on 2/9/2023 in #support
Add Index to Attribute
I have this
AshProstgres
resource and would like to add an index to the link
parameter. How can I do that?
2 replies
AEAsh Elixir
•Created by Stefan Wintermeyer on 2/9/2023 in #support
Create a Unique Attribute
I have this
AshPostgres
resource and want to make sure the the title
is unique. How can I do that?
5 replies
AEAsh Elixir
•Created by Stefan Wintermeyer on 1/29/2023 in #support
Use secret_key_base as token_signing_secret
I have the following code in
lib/example/accounts/user.ex
:
Is there a way to use the secret_key_base
which is already set in the Phoenix Application config instead of System.fetch_env("TOKEN_SIGNING_SECRET")
?7 replies
AEAsh Elixir
•Created by Stefan Wintermeyer on 1/29/2023 in #support
type "citext" does not exist
During the "Integrating Ash Authentication and Phoenix" tutorial I get this migration:
That results in the following error:
https://hexdocs.pm/ash_postgres/AshPostgres.Repo.html says that I need to install the
citext
extension. But how do I do that?
There is the following example code but I don't know where to put it.9 replies
AEAsh Elixir
•Created by Stefan Wintermeyer on 1/26/2023 in #support
One or multiple registry.ex in an Ash project?
5 replies
AEAsh Elixir
•Created by Stefan Wintermeyer on 1/26/2023 in #support
FeriendatenWeb.AuthController.init/1 is undefined
https://github.com/team-alembic/ash_authentication_phoenix says "This is beta software. Please don't use it without talking to us!". I did use it without talking to you and here we are. 😉
I followed the installation manual for a Phoenix application. When I try to start the server with
mix phx.server
I'll get the error message FeriendatenWeb.AuthController.init/1 is undefined (module FeriendatenWeb.AuthController is not available or is yet to be defined)``
I've never created an
AuthController` because the installation manual didn't say so. Is there a step by step tutorial how to start with a vanilla Phoenix application?17 replies