NDaniil
NDaniil
AEAsh Elixir
Created by NDaniil on 5/13/2023 in #support
How to read resource without actions
I'm trying to inspect MyApp.Accounts.Token using iex, but I'm getting NoPrimaryAction error. Is it possible to inspect resources without defining read action? Is there a way to convert it to Ecto.Schema, so I can use Ecto.Query?
> MyApp.Accounts.read(MyApp.Accounts.Token)
{:error,
%Ash.Error.Invalid{
errors: [
%Ash.Error.Invalid.NoPrimaryAction{
resource: MyApp.Accounts.Token,
type: :read,
changeset: nil,
query: nil,
error_context: [],
vars: [],
path: [],
stacktrace: #Stacktrace<>,
class: :invalid
}
],
stacktraces?: true,
changeset: nil,
query: nil,
error_context: [],
vars: [],
path: [],
stacktrace: #Stacktrace<>,
class: :invalid
}}
> MyApp.Accounts.read(MyApp.Accounts.Token)
{:error,
%Ash.Error.Invalid{
errors: [
%Ash.Error.Invalid.NoPrimaryAction{
resource: MyApp.Accounts.Token,
type: :read,
changeset: nil,
query: nil,
error_context: [],
vars: [],
path: [],
stacktrace: #Stacktrace<>,
class: :invalid
}
],
stacktraces?: true,
changeset: nil,
query: nil,
error_context: [],
vars: [],
path: [],
stacktrace: #Stacktrace<>,
class: :invalid
}}
defmodule MyApp.Accounts.Token do
use Ash.Resource,
data_layer: AshPostgres.DataLayer,
extensions: [AshAuthentication.TokenResource]

token do
api MyApp.Accounts
end

postgres do
table "tokens"
repo MyApp.Repo
end
end
defmodule MyApp.Accounts.Token do
use Ash.Resource,
data_layer: AshPostgres.DataLayer,
extensions: [AshAuthentication.TokenResource]

token do
api MyApp.Accounts
end

postgres do
table "tokens"
repo MyApp.Repo
end
end
3 replies