xSHYNE
xSHYNE
AEAsh Elixir
Created by xSHYNE on 8/10/2023 in #support
DISTINCT ON LEAST() GREATEST()
I certainly can, will still need fragments I think for least and greatest i think, but that makes some sense.
7 replies
AEAsh Elixir
Created by xSHYNE on 8/10/2023 in #support
DISTINCT ON LEAST() GREATEST()
Gonna go that route I think is best. Just wondering if there's a better way someone smarter with SQL or a way to write it that sort of still fits into the nicely compact Ash box
7 replies
AEAsh Elixir
Created by xSHYNE on 7/20/2023 in #support
Policy checks on related resources
in case anyone else finds it useful: this seemed to work:
defmodule Digsync.Accounts.Policies.IsGroupAdmin do
use Ash.Policy.SimpleCheck

alias Digsync.Accounts
alias Digsync.Accounts.Group
alias Digsync.Accounts.GroupRequest

def describe(_) do
"Check to see if the actor is a group admin"
end

def match?(actor, %{resource: GroupRequest, changeset: changeset}, _opts) do
group = get_group(changeset)

group.group_admin_id == actor.id
end

def match?(actor, %{resource: GroupMembership, changeset: changeset}, _opts) do
group = get_group(changeset)

group.group_admin_id == actor.id
end

def match?(_, _, _), do: false

defp get_group(changeset) do
changeset
|> Ash.Changeset.get_argument(:group)
|> then(&(Group |> Accounts.get!(&1)))
end
end
defmodule Digsync.Accounts.Policies.IsGroupAdmin do
use Ash.Policy.SimpleCheck

alias Digsync.Accounts
alias Digsync.Accounts.Group
alias Digsync.Accounts.GroupRequest

def describe(_) do
"Check to see if the actor is a group admin"
end

def match?(actor, %{resource: GroupRequest, changeset: changeset}, _opts) do
group = get_group(changeset)

group.group_admin_id == actor.id
end

def match?(actor, %{resource: GroupMembership, changeset: changeset}, _opts) do
group = get_group(changeset)

group.group_admin_id == actor.id
end

def match?(_, _, _), do: false

defp get_group(changeset) do
changeset
|> Ash.Changeset.get_argument(:group)
|> then(&(Group |> Accounts.get!(&1)))
end
end
10 replies
AEAsh Elixir
Created by xSHYNE on 7/20/2023 in #support
Policy checks on related resources
Ah it was for reads I get the Query instead. durp.
10 replies
AEAsh Elixir
Created by xSHYNE on 7/20/2023 in #support
Policy checks on related resources
Ok I'm going to give that a shot, I for some reason tried this and didn't think I had access to the changeset, maybe it was on a different action? but I just checked and clearly I do. One more short question, I saw on Ash.Policy.Check there is an auto_filter() option .. I'm taking a stab at guessing here... can I use that to always filter by the argument passed in ... i.e. always filter a group_request by the group_id arg passed in when doing actions?
10 replies
AEAsh Elixir
Created by xSHYNE on 7/13/2023 in #support
manage_relationship argument not relating primary key to resource
🙂
22 replies
AEAsh Elixir
Created by xSHYNE on 7/13/2023 in #support
manage_relationship argument not relating primary key to resource
Appreciate the quick help
22 replies
AEAsh Elixir
Created by xSHYNE on 7/13/2023 in #support
manage_relationship argument not relating primary key to resource
It looks like an accident but not sure how that happened
22 replies
AEAsh Elixir
Created by xSHYNE on 7/13/2023 in #support
manage_relationship argument not relating primary key to resource
Ash.Resource.Info.primary_key(Group)
[:id, :creator_id]
Ash.Resource.Info.primary_key(Group)
[:id, :creator_id]
22 replies
AEAsh Elixir
Created by xSHYNE on 7/13/2023 in #support
manage_relationship argument not relating primary key to resource
Ah I think I have two relationships
22 replies
AEAsh Elixir
Created by xSHYNE on 7/13/2023 in #support
manage_relationship argument not relating primary key to resource
Table "public.groups"
Column | Type | Collation | Nullable | Default
--------------------+-----------------------------+-----------+----------+--------------------
id | uuid | | not null | uuid_generate_v4()
...
"groups_pkey" PRIMARY KEY, btree (id, creator_id)
Table "public.groups"
Column | Type | Collation | Nullable | Default
--------------------+-----------------------------+-----------+----------+--------------------
id | uuid | | not null | uuid_generate_v4()
...
"groups_pkey" PRIMARY KEY, btree (id, creator_id)
22 replies
AEAsh Elixir
Created by xSHYNE on 7/13/2023 in #support
manage_relationship argument not relating primary key to resource
iex(3)> uuid = Ash.Type.cast_input(:uuid, "b6937067-651d-4385-8323-20f193f03cd9")
{:ok, "b6937067-651d-4385-8323-20f193f03cd9"}
iex(4)> {:ok, uuid} = v
{:ok, "b6937067-651d-4385-8323-20f193f03cd9"}
iex(5)> Accounts.get!(Group, uuid)
** (Ash.Error.Invalid) Input Invalid

* invalid primary key "b6937067-651d-4385-8323-20f193f03cd9" provided
(ash 2.11.6) lib/ash/filter/filter.ex:464: Ash.Filter.get_filter/2
iex(3)> uuid = Ash.Type.cast_input(:uuid, "b6937067-651d-4385-8323-20f193f03cd9")
{:ok, "b6937067-651d-4385-8323-20f193f03cd9"}
iex(4)> {:ok, uuid} = v
{:ok, "b6937067-651d-4385-8323-20f193f03cd9"}
iex(5)> Accounts.get!(Group, uuid)
** (Ash.Error.Invalid) Input Invalid

* invalid primary key "b6937067-651d-4385-8323-20f193f03cd9" provided
(ash 2.11.6) lib/ash/filter/filter.ex:464: Ash.Filter.get_filter/2
22 replies
AEAsh Elixir
Created by xSHYNE on 7/13/2023 in #support
manage_relationship argument not relating primary key to resource
lemme try that
attributes do
uuid_primary_key(:id)

attribute :name, :string do
allow_nil? false

constraints min_length: 3,
trim?: true,
allow_empty?: false
end

attribute :description, :string do
allow_nil? false
end

attribute :locaton, :string

attribute :preferred_location, :string

attribute :type, :atom do
default :social
constraints one_of: [:club, :bar, :social]
end

create_timestamp(:inserted_at, private?: false, allow_nil?: false)
create_timestamp(:updated_at, private?: false, allow_nil?: false)
end
attributes do
uuid_primary_key(:id)

attribute :name, :string do
allow_nil? false

constraints min_length: 3,
trim?: true,
allow_empty?: false
end

attribute :description, :string do
allow_nil? false
end

attribute :locaton, :string

attribute :preferred_location, :string

attribute :type, :atom do
default :social
constraints one_of: [:club, :bar, :social]
end

create_timestamp(:inserted_at, private?: false, allow_nil?: false)
create_timestamp(:updated_at, private?: false, allow_nil?: false)
end
22 replies
AEAsh Elixir
Created by xSHYNE on 7/13/2023 in #support
manage_relationship argument not relating primary key to resource
digsync_dev=# select id from groups;
id
--------------------------------------
b6937067-651d-4385-8323-20f193f03cd9
(1 row)
digsync_dev=# select id from groups;
id
--------------------------------------
b6937067-651d-4385-8323-20f193f03cd9
(1 row)
22 replies
AEAsh Elixir
Created by xSHYNE on 7/13/2023 in #support
manage_relationship argument not relating primary key to resource
iex(40)> Accounts.get!(Group, "b6937067-651d-4385-8323-20f193f03cd9")
** (Ash.Error.Invalid) Input Invalid

* invalid primary key "b6937067-651d-4385-8323-20f193f03cd9" provided
iex(40)> Accounts.get!(Group, "b6937067-651d-4385-8323-20f193f03cd9")
** (Ash.Error.Invalid) Input Invalid

* invalid primary key "b6937067-651d-4385-8323-20f193f03cd9" provided
22 replies
AEAsh Elixir
Created by xSHYNE on 7/13/2023 in #support
manage_relationship argument not relating primary key to resource
actions do
defaults([:read, :update, :destroy])

create :create do
change relate_actor(:creator)
end
end
actions do
defaults([:read, :update, :destroy])

create :create do
change relate_actor(:creator)
end
end
22 replies
AEAsh Elixir
Created by xSHYNE on 7/13/2023 in #support
manage_relationship argument not relating primary key to resource
default
22 replies
AEAsh Elixir
Created by xSHYNE on 7/12/2023 in #support
Ash Admin dependency for newest liveview
👍
4 replies
AEAsh Elixir
Created by xSHYNE on 7/12/2023 in #support
Ash Admin dependency for newest liveview
ty sir
4 replies
AEAsh Elixir
Created by xSHYNE on 7/7/2023 in #support
Ash.Query.load not loading nested relationship?
ok thank u i'll give it a shot
19 replies