Stefan Wintermeyer
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
[...]
create :create do
primary? true
argument :tags, {:array, :map}

argument :add_tag, :map do
allow_nil? false
end

change manage_relationship(:tags, type: :append_and_remove, on_no_match: :create)
change manage_relationship(:add_tag, :tags, type: :create)
end
[...]
[...]
create :create do
primary? true
argument :tags, {:array, :map}

argument :add_tag, :map do
allow_nil? false
end

change manage_relationship(:tags, type: :append_and_remove, on_no_match: :create)
change manage_relationship(:add_tag, :tags, type: :create)
end
[...]
This works nicely:
iex(6)> banana = App.Shop.Product.create!(%{name: "Banana", add_tag: %{name: "Yellow"}})
iex(6)> banana = App.Shop.Product.create!(%{name: "Banana", add_tag: %{name: "Yellow"}})
Unfortunately I can also add another "Yellow" tag via an update:
iex(7)> App.Shop.Product.update!(banana, %{add_tag: %{name: "Yellow"}}).tags |> Enum.map(& &1.name)
["Yellow", "Yellow"]
iex(7)> App.Shop.Product.update!(banana, %{add_tag: %{name: "Yellow"}}).tags |> Enum.map(& &1.name)
["Yellow", "Yellow"]
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
defmodule App.Shop.Product do
[...]
relationships do
many_to_many :tags, App.Shop.Tag do
through App.Shop.ProductTag
source_attribute_on_join_resource :product_id
destination_attribute_on_join_resource :tag_id
end
end

actions do
defaults [:read]

create :create do
primary? true
argument :tags, {:array, :map}

argument :add_tag, :map do
allow_nil? false
end

change manage_relationship(:tags, type: :append_and_remove, on_no_match: :create)
change manage_relationship(:add_tag, :tags, type: :create)
end

update :update do
primary? true
argument :tags, {:array, :map}

argument :add_tag, :map do
allow_nil? false
end

change manage_relationship(:tags, type: :append_and_remove, on_no_match: :create)
change manage_relationship(:add_tag, :tags, type: :create)
end
end

code_interface do
define_for App.Shop
define :create
define :read
define :update
end
end
defmodule App.Shop.Product do
[...]
relationships do
many_to_many :tags, App.Shop.Tag do
through App.Shop.ProductTag
source_attribute_on_join_resource :product_id
destination_attribute_on_join_resource :tag_id
end
end

actions do
defaults [:read]

create :create do
primary? true
argument :tags, {:array, :map}

argument :add_tag, :map do
allow_nil? false
end

change manage_relationship(:tags, type: :append_and_remove, on_no_match: :create)
change manage_relationship(:add_tag, :tags, type: :create)
end

update :update do
primary? true
argument :tags, {:array, :map}

argument :add_tag, :map do
allow_nil? false
end

change manage_relationship(:tags, type: :append_and_remove, on_no_match: :create)
change manage_relationship(:add_tag, :tags, type: :create)
end
end

code_interface do
define_for App.Shop
define :create
define :read
define :update
end
end
I get this error:
iex(1)> App.Shop.Product.create!(%{name: "Banana"}, add_tag: %{name: "Yellow"})
** (Ash.Error.Unknown) Unknown Error

* %NimbleOptions.ValidationError{message: "unknown options [:add_tag], valid options are: [:upsert?, :upsert_identity, :upsert_fields, :internal?, :timeout, :tracer, :verbose?, :action, :authorize?, :stacktraces?, :tenant, :actor, :after_action, :return_notifications?, :notification_metadata]", key: [:add_tag], value: nil, keys_path: []}
(ash 2.14.18) lib/ash/api/api.ex:2179: Ash.Api.unwrap_or_raise!/3
iex(1)> App.Shop.Product.create!(%{name: "Banana"}, add_tag: %{name: "Yellow"})
** (Ash.Error.Unknown) Unknown Error

* %NimbleOptions.ValidationError{message: "unknown options [:add_tag], valid options are: [:upsert?, :upsert_identity, :upsert_fields, :internal?, :timeout, :tracer, :verbose?, :action, :authorize?, :stacktraces?, :tenant, :actor, :after_action, :return_notifications?, :notification_metadata]", key: [:add_tag], value: nil, keys_path: []}
(ash 2.14.18) lib/ash/api/api.ex:2179: Ash.Api.unwrap_or_raise!/3
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
defmodule App.Shop.Product do
use Ash.Resource, data_layer: Ash.DataLayer.Ets

attributes do
uuid_primary_key :id
attribute :name, :string
attribute :price, :decimal
end

relationships do
many_to_many :tags, App.Shop.Tag do
through App.Shop.ProductTag
source_attribute_on_join_resource :product_id
destination_attribute_on_join_resource :tag_id
end
end

actions do
defaults [:read, :destroy]

create :create do
primary? true
argument :tags, {:array, :map}
change manage_relationship(:tags, type: :append_and_remove, on_no_match: :create)
end

create :update do
argument :tags, {:array, :map}
change manage_relationship(:tags, type: :append_and_remove, on_no_match: :create)
end
end

code_interface do
define_for App.Shop
define :create
define :read
define :by_name, get_by: [:name], action: :read
define :update
define :destroy
end
end
defmodule App.Shop.Product do
use Ash.Resource, data_layer: Ash.DataLayer.Ets

attributes do
uuid_primary_key :id
attribute :name, :string
attribute :price, :decimal
end

relationships do
many_to_many :tags, App.Shop.Tag do
through App.Shop.ProductTag
source_attribute_on_join_resource :product_id
destination_attribute_on_join_resource :tag_id
end
end

actions do
defaults [:read, :destroy]

create :create do
primary? true
argument :tags, {:array, :map}
change manage_relationship(:tags, type: :append_and_remove, on_no_match: :create)
end

create :update do
argument :tags, {:array, :map}
change manage_relationship(:tags, type: :append_and_remove, on_no_match: :create)
end
end

code_interface do
define_for App.Shop
define :create
define :read
define :by_name, get_by: [:name], action: :read
define :update
define :destroy
end
end
Here's what I do in the iex:
iex(1)> good_deal_tag = App.Shop.Tag.create!(%{name: "Good deal"})
iex(2)> yellow_tag = App.Shop.Tag.create!(%{name: "Yellow"})
iex(3)> App.Shop.Product.create!(%{
name: "Banana",
tags: [good_deal_tag, yellow_tag]
})
iex(4) banana = App.Shop.Product.by_name!("Banana", load: [:tags])
iex(1)> good_deal_tag = App.Shop.Tag.create!(%{name: "Good deal"})
iex(2)> yellow_tag = App.Shop.Tag.create!(%{name: "Yellow"})
iex(3)> App.Shop.Product.create!(%{
name: "Banana",
tags: [good_deal_tag, yellow_tag]
})
iex(4) banana = App.Shop.Product.by_name!("Banana", load: [:tags])
That all works nicely. But I can not update the products tags or the even the product:
iex(16)> App.Shop.Product.update!(banana, %{tags: [yellow_tag]})
** (FunctionClauseError) no function clause matching in Keyword.split/2
[...]
iex(16)> App.Shop.Product.update!(banana, %{name: "test"})
** (FunctionClauseError) no function clause matching in Keyword.split/2
iex(16)> App.Shop.Product.update!(banana, %{tags: [yellow_tag]})
** (FunctionClauseError) no function clause matching in Keyword.split/2
[...]
iex(16)> App.Shop.Product.update!(banana, %{name: "test"})
** (FunctionClauseError) no function clause matching in Keyword.split/2
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
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:
defmodule App.Shop.Product do
[...]
relationships do
many_to_many :tags, App.Shop.Tag do
through App.Shop.ProductTag
source_attribute_on_join_resource :product_id
destination_attribute_on_join_resource :tag_id
end
end

actions do
defaults [:create, :read]
end

code_interface do
define_for App.Shop
define :create
define :read
define :by_name, get_by: [:name], action: :read
end
end
defmodule App.Shop.Product do
[...]
relationships do
many_to_many :tags, App.Shop.Tag do
through App.Shop.ProductTag
source_attribute_on_join_resource :product_id
destination_attribute_on_join_resource :tag_id
end
end

actions do
defaults [:create, :read]
end

code_interface do
define_for App.Shop
define :create
define :read
define :by_name, get_by: [:name], action: :read
end
end
defmodule App.Shop.Tag do
[...]

relationships do
many_to_many :products, App.Shop.Product do
through App.Shop.ProductTag
source_attribute_on_join_resource :tag_id
destination_attribute_on_join_resource :product_id
end
end

actions do
defaults [:create, :read]
end

code_interface do
define_for App.Shop
define :create
define :read
define :by_name, get_by: [:name], action: :read
end
end
defmodule App.Shop.Tag do
[...]

relationships do
many_to_many :products, App.Shop.Product do
through App.Shop.ProductTag
source_attribute_on_join_resource :tag_id
destination_attribute_on_join_resource :product_id
end
end

actions do
defaults [:create, :read]
end

code_interface do
define_for App.Shop
define :create
define :read
define :by_name, get_by: [:name], action: :read
end
end
defmodule App.Shop.ProductTag do
use Ash.Resource, data_layer: Ash.DataLayer.Ets

relationships do
belongs_to :product, App.Shop.Product do
primary_key? true
allow_nil? false
end

belongs_to :tag, App.Shop.Tag do
primary_key? true
allow_nil? false
end
end
end
defmodule App.Shop.ProductTag do
use Ash.Resource, data_layer: Ash.DataLayer.Ets

relationships do
belongs_to :product, App.Shop.Product do
primary_key? true
allow_nil? false
end

belongs_to :tag, App.Shop.Tag do
primary_key? true
allow_nil? false
end
end
end
The iex preparation:
iex(1)> good_deal_tag = App.Shop.Tag.create!(%{name: "Good deal"})
iex(2)> yellow_tag = App.Shop.Tag.create!(%{name: "Yellow"})
iex(1)> good_deal_tag = App.Shop.Tag.create!(%{name: "Good deal"})
iex(2)> yellow_tag = App.Shop.Tag.create!(%{name: "Yellow"})
Question: How can I create a new product which has the two tags good_deal_tag and yellow_tag? Something like:
iex(3) App.Shop.Product.create!(%{name: "Banana", tags: [good_deal_tag, yellow_tag]})
iex(3) App.Shop.Product.create!(%{name: "Banana", tags: [good_deal_tag, yellow_tag]})
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
defmodule App.Shop.Product do
[...]
relationships do
belongs_to :category, App.Shop.Category do
attribute_writable? true
end
end
[...]
end
defmodule App.Shop.Product do
[...]
relationships do
belongs_to :category, App.Shop.Category do
attribute_writable? true
end
end
[...]
end
I want to query for the product "Banana":
iex(12)> fruits = App.Shop.Category.create!(%{name: "Fruits"})
#App.Shop.Category<
__meta__: #Ecto.Schema.Metadata<:loaded>,
id: "3a3ed806-6df4-4602-aff6-4eed50e814b2",
name: "Fruits",
...
>
iex(13)> banana = App.Shop.Product.create!(%{name: "Banana", price: 0.1, category_id: fruits.id})
#App.Shop.Product<
promotion: #Ash.NotLoaded<:relationship>,
category: #Ash.NotLoaded<:relationship>,
__meta__: #Ecto.Schema.Metadata<:loaded>,
id: "d655fa01-ece5-4ad9-b927-764a6a48b165",
name: "Banana",
price: Decimal.new("0.1"),
category_id: "3a3ed806-6df4-4602-aff6-4eed50e814b2",
...
>
iex(14)> App.Shop.Product.by_name("Banana")
{:ok,
#App.Shop.Product<
promotion: #Ash.NotLoaded<:relationship>,
category: #Ash.NotLoaded<:relationship>,
__meta__: #Ecto.Schema.Metadata<:loaded>,
id: "d655fa01-ece5-4ad9-b927-764a6a48b165",
name: "Banana",
price: Decimal.new("0.1"),
category_id: "3a3ed806-6df4-4602-aff6-4eed50e814b2",
...
>}
iex(15)> App.Shop.load(banana, :category)
{:ok,
#App.Shop.Product<
promotion: #Ash.NotLoaded<:relationship>,
category: #App.Shop.Category<
__meta__: #Ecto.Schema.Metadata<:loaded>,
id: "3a3ed806-6df4-4602-aff6-4eed50e814b2",
name: "Fruits",
...
>,
__meta__: #Ecto.Schema.Metadata<:loaded>,
id: "d655fa01-ece5-4ad9-b927-764a6a48b165",
name: "Banana",
price: Decimal.new("0.1"),
category_id: "3a3ed806-6df4-4602-aff6-4eed50e814b2",
...
>}
iex(12)> fruits = App.Shop.Category.create!(%{name: "Fruits"})
#App.Shop.Category<
__meta__: #Ecto.Schema.Metadata<:loaded>,
id: "3a3ed806-6df4-4602-aff6-4eed50e814b2",
name: "Fruits",
...
>
iex(13)> banana = App.Shop.Product.create!(%{name: "Banana", price: 0.1, category_id: fruits.id})
#App.Shop.Product<
promotion: #Ash.NotLoaded<:relationship>,
category: #Ash.NotLoaded<:relationship>,
__meta__: #Ecto.Schema.Metadata<:loaded>,
id: "d655fa01-ece5-4ad9-b927-764a6a48b165",
name: "Banana",
price: Decimal.new("0.1"),
category_id: "3a3ed806-6df4-4602-aff6-4eed50e814b2",
...
>
iex(14)> App.Shop.Product.by_name("Banana")
{:ok,
#App.Shop.Product<
promotion: #Ash.NotLoaded<:relationship>,
category: #Ash.NotLoaded<:relationship>,
__meta__: #Ecto.Schema.Metadata<:loaded>,
id: "d655fa01-ece5-4ad9-b927-764a6a48b165",
name: "Banana",
price: Decimal.new("0.1"),
category_id: "3a3ed806-6df4-4602-aff6-4eed50e814b2",
...
>}
iex(15)> App.Shop.load(banana, :category)
{:ok,
#App.Shop.Product<
promotion: #Ash.NotLoaded<:relationship>,
category: #App.Shop.Category<
__meta__: #Ecto.Schema.Metadata<:loaded>,
id: "3a3ed806-6df4-4602-aff6-4eed50e814b2",
name: "Fruits",
...
>,
__meta__: #Ecto.Schema.Metadata<:loaded>,
id: "d655fa01-ece5-4ad9-b927-764a6a48b165",
name: "Banana",
price: Decimal.new("0.1"),
category_id: "3a3ed806-6df4-4602-aff6-4eed50e814b2",
...
>}
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
defmodule App.Shop.Category do
use Ash.Resource, data_layer: Ash.DataLayer.Ets

attributes do
uuid_primary_key :id
attribute :name, :string
end

actions do
defaults [:create, :read]
end

code_interface do
define_for App.Shop
define :create
define :read
end
end
defmodule App.Shop.Category do
use Ash.Resource, data_layer: Ash.DataLayer.Ets

attributes do
uuid_primary_key :id
attribute :name, :string
end

actions do
defaults [:create, :read]
end

code_interface do
define_for App.Shop
define :create
define :read
end
end
lib/app/shop/resources/product.ex
defmodule App.Shop.Product do
use Ash.Resource, data_layer: Ash.DataLayer.Ets

attributes do
uuid_primary_key :id
attribute :name, :string
attribute :price, :decimal
end

relationships do
belongs_to :category, App.Shop.Category
end

actions do
defaults [:create, :read]
end

code_interface do
define_for App.Shop
define :create
define :read
end
end
defmodule App.Shop.Product do
use Ash.Resource, data_layer: Ash.DataLayer.Ets

attributes do
uuid_primary_key :id
attribute :name, :string
attribute :price, :decimal
end

relationships do
belongs_to :category, App.Shop.Category
end

actions do
defaults [:create, :read]
end

code_interface do
define_for App.Shop
define :create
define :read
end
end
Question: How can I create a new Product which includes a Category? This is what I tried:
iex(1)> fruits = App.Shop.Category.create!(%{name: "Fruits"})
#App.Shop.Category<
__meta__: #Ecto.Schema.Metadata<:loaded>,
id: "5b582e8a-3c19-4ce4-b609-88748a46e2ce",
name: "Fruits",
aggregates: %{},
calculations: %{},
...
>
iex(3)> orange = App.Shop.Product.create!(%{name: "Orange", price: 0.20, category: fruits})
#App.Shop.Product<
category: #Ash.NotLoaded<:relationship>,
__meta__: #Ecto.Schema.Metadata<:loaded>,
id: "432152d7-715d-4731-8fe4-ed90b05ee30e",
name: "Orange",
price: Decimal.new("0.2"),
category_id: nil,
aggregates: %{},
calculations: %{},
...
>
iex(4)> orange = App.Shop.Product.create!(%{name: "Orange", price: 0.20, category_id: fruits.id})
#App.Shop.Product<
category: #Ash.NotLoaded<:relationship>,
__meta__: #Ecto.Schema.Metadata<:loaded>,
id: "68c1023e-5b57-4819-a4a2-ff16f7efdc5d",
name: "Orange",
price: Decimal.new("0.2"),
category_id: nil,
aggregates: %{},
calculations: %{},
...
>
iex(5)>
iex(1)> fruits = App.Shop.Category.create!(%{name: "Fruits"})
#App.Shop.Category<
__meta__: #Ecto.Schema.Metadata<:loaded>,
id: "5b582e8a-3c19-4ce4-b609-88748a46e2ce",
name: "Fruits",
aggregates: %{},
calculations: %{},
...
>
iex(3)> orange = App.Shop.Product.create!(%{name: "Orange", price: 0.20, category: fruits})
#App.Shop.Product<
category: #Ash.NotLoaded<:relationship>,
__meta__: #Ecto.Schema.Metadata<:loaded>,
id: "432152d7-715d-4731-8fe4-ed90b05ee30e",
name: "Orange",
price: Decimal.new("0.2"),
category_id: nil,
aggregates: %{},
calculations: %{},
...
>
iex(4)> orange = App.Shop.Product.create!(%{name: "Orange", price: 0.20, category_id: fruits.id})
#App.Shop.Product<
category: #Ash.NotLoaded<:relationship>,
__meta__: #Ecto.Schema.Metadata<:loaded>,
id: "68c1023e-5b57-4819-a4a2-ff16f7efdc5d",
name: "Orange",
price: Decimal.new("0.2"),
category_id: nil,
aggregates: %{},
calculations: %{},
...
>
iex(5)>
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:
attributes do
uuid_primary_key :id

attribute :content, :string do
allow_nil? false
constraints: [min_length: 1, max_length: 255]
end
end
attributes do
uuid_primary_key :id

attribute :content, :string do
allow_nil? false
constraints: [min_length: 1, max_length: 255]
end
end
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
code_interface do
define_for Office.ToDoList
define :create, args: [:subject]
end
code_interface do
define_for Office.ToDoList
define :create, args: [:subject]
end
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:
defmodule Example.Blog.Post do
use Ash.Resource,
data_layer: AshPostgres.DataLayer

attributes do
uuid_primary_key :id

attribute :content, :string do
allow_nil? false
end
end

postgres do
table "blog_posts"
repo Example.Repo
end

actions do
defaults [:create, :read]
end
end
defmodule Example.Blog.Post do
use Ash.Resource,
data_layer: AshPostgres.DataLayer

attributes do
uuid_primary_key :id

attribute :content, :string do
allow_nil? false
end
end

postgres do
table "blog_posts"
repo Example.Repo
end

actions do
defaults [:create, :read]
end
end
defmodule Example.Blog.Tag do
use Ash.Resource,
data_layer: AshPostgres.DataLayer

attributes do
uuid_primary_key :id

attribute :name, :string do
allow_nil? false
end
end

postgres do
table "tags"
repo Example.Repo
end

actions do
defaults [:create, :read]
end
end
defmodule Example.Blog.Tag do
use Ash.Resource,
data_layer: AshPostgres.DataLayer

attributes do
uuid_primary_key :id

attribute :name, :string do
allow_nil? false
end
end

postgres do
table "tags"
repo Example.Repo
end

actions do
defaults [:create, :read]
end
end
- 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:
[post] = MyApp.Post
|> Ash.Query.filter(id == "bc38fcb3-080d-46ba-834d-5as58d689sda")
|> Ash.Query.limit(1)
|> MyApp.Api.read!()
[post] = MyApp.Post
|> Ash.Query.filter(id == "bc38fcb3-080d-46ba-834d-5as58d689sda")
|> Ash.Query.limit(1)
|> MyApp.Api.read!()
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:
:map -> Ash.Type.Map
:term -> Ash.Type.Term
:atom -> Ash.Type.Atom
:string -> Ash.Type.String
:integer -> Ash.Type.Integer
:float -> Ash.Type.Float
:duration_name -> Ash.Type.DurationName
:function -> Ash.Type.Function
:boolean -> Ash.Type.Boolean
:struct -> Ash.Type.Struct
:uuid -> Ash.Type.UUID
:binary -> Ash.Type.Binary
:date -> Ash.Type.Date
:time -> Ash.Type.Time
:decimal -> Ash.Type.Decimal
:ci_string -> Ash.Type.CiString
:naive_datetime -> Ash.Type.NaiveDatetime
:utc_datetime -> Ash.Type.UtcDatetime
:utc_datetime_usec -> Ash.Type.UtcDatetimeUsec
:url_encoded_binary -> Ash.Type.UrlEncodedBinary
:map -> Ash.Type.Map
:term -> Ash.Type.Term
:atom -> Ash.Type.Atom
:string -> Ash.Type.String
:integer -> Ash.Type.Integer
:float -> Ash.Type.Float
:duration_name -> Ash.Type.DurationName
:function -> Ash.Type.Function
:boolean -> Ash.Type.Boolean
:struct -> Ash.Type.Struct
:uuid -> Ash.Type.UUID
:binary -> Ash.Type.Binary
:date -> Ash.Type.Date
:time -> Ash.Type.Time
:decimal -> Ash.Type.Decimal
:ci_string -> Ash.Type.CiString
:naive_datetime -> Ash.Type.NaiveDatetime
:utc_datetime -> Ash.Type.UtcDatetime
:utc_datetime_usec -> Ash.Type.UtcDatetimeUsec
:url_encoded_binary -> Ash.Type.UrlEncodedBinary
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?
attributes do
uuid_primary_key :id

attribute :link, :string do
allow_nil? false
end
end
attributes do
uuid_primary_key :id

attribute :link, :string do
allow_nil? false
end
end
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?
attributes do
uuid_primary_key :id

attribute :title, :string do
allow_nil? false
end
end
attributes do
uuid_primary_key :id

attribute :title, :string do
allow_nil? false
end
end
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:
tokens do
enabled? true
token_resource Example.Accounts.Token
signing_secret fn _, _ ->
System.fetch_env("TOKEN_SIGNING_SECRET")
end
end
tokens do
enabled? true
token_resource Example.Accounts.Token
signing_secret fn _, _ ->
System.fetch_env("TOKEN_SIGNING_SECRET")
end
end
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:
create table(:users, primary_key: false) do
add :id, :uuid, null: false, primary_key: true
add :email, :citext, null: false
# ^^^^^^^
add :hashed_password, :text, null: false
end
create table(:users, primary_key: false) do
add :id, :uuid, null: false, primary_key: true
add :email, :citext, null: false
# ^^^^^^^
add :hashed_password, :text, null: false
end
That results in the following error:
12:42:19.145 [info] create table users
** (Postgrex.Error) ERROR 42704 (undefined_object) type "citext" does not exist
(ecto_sql 3.9.2) lib/ecto/adapters/sql.ex:913: Ecto.Adapters.SQL.raise_sql_call_error/1
12:42:19.145 [info] create table users
** (Postgrex.Error) ERROR 42704 (undefined_object) type "citext" does not exist
(ecto_sql 3.9.2) lib/ecto/adapters/sql.ex:913: Ecto.Adapters.SQL.raise_sql_call_error/1
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