Resources without primary key not supported

I have this code:
defmodule Scribble.EmailHandler.User do
use Ash.Resource
use Ash.Resource, data_layer: Ash.DataLayer.Ets

actions do
defaults [:create, :read]
end

attributes do
uuid_primary_key :id

attribute :email, :string, allow_nil?: false
attribute :name, :string, allow_nil?: false
attribute :reply_email, :string
create_timestamp :inserted_at
update_timestamp :updated_at
end

calculations do
calculate :response_email, :string, expr(reply_email || email)
end
end
defmodule Scribble.EmailHandler.User do
use Ash.Resource
use Ash.Resource, data_layer: Ash.DataLayer.Ets

actions do
defaults [:create, :read]
end

attributes do
uuid_primary_key :id

attribute :email, :string, allow_nil?: false
attribute :name, :string, allow_nil?: false
attribute :reply_email, :string
create_timestamp :inserted_at
update_timestamp :updated_at
end

calculations do
calculate :response_email, :string, expr(reply_email || email)
end
end
And since adding the data layer I'm getting "Resources without a primary key are not supported" But I have the uuid_primary_key. Am I doing something wrong?
3 Replies
frankdugan3
frankdugan33y ago
Could it be because you are calling use Ash.Resource twice? :thinkies:
rohan
rohanOP3y ago
....yes 🤦‍♂️
frankdugan3
frankdugan33y ago
Macros can be tricky sometimes. 😄

Did you find this page helpful?