richaard0
richaard0
AEAsh Elixir
Created by richaard0 on 7/3/2023 in #support
Expected at most one result but got ...
I'm not sure if I've encountered a bug or not. I have the following action:
read :get do
argument :id, :uuid
get? true
end
read :get do
argument :id, :uuid
get? true
end
and the following associated code interface:
define :get do
args [:id]
end
define :get do
args [:id]
end
I expect it to return at most one result. In iex, if I call the following:
iex(11)> Flight.get("a8c463a0-2ae0-4f04-8fbe-7bb1abe94ff6", tenant: "8f251331-d27b-4d42-a05b-5dbe3e019ebe")
iex(11)> Flight.get("a8c463a0-2ae0-4f04-8fbe-7bb1abe94ff6", tenant: "8f251331-d27b-4d42-a05b-5dbe3e019ebe")
I receive the following error:
{:error,
%Ash.Error.Invalid{
errors: [
%Ash.Error.Invalid.MultipleResults{
count: 5,
.....
}
{:error,
%Ash.Error.Invalid{
errors: [
%Ash.Error.Invalid.MultipleResults{
count: 5,
.....
}
I confirmed that my record exists and that there is only one in my DB. More interestingly, here's the query that's being performed:
[debug] QUERY OK source="flights" db=11.9ms queue=0.1ms idle=283.7ms
SELECT f0."id", f0."number", f0."departure_time", f0."arrival_time", f0."airline_id", f0."departure", f0."arrival", f0."alternate", f0."user_id", f0."plane_id" FROM "flights" AS f0 WHERE (f0."airline_id"::uuid = $1::uuid) ["8f251331-d27b-4d42-a05b-5dbe3e019ebe"]
[debug] QUERY OK source="flights" db=11.9ms queue=0.1ms idle=283.7ms
SELECT f0."id", f0."number", f0."departure_time", f0."arrival_time", f0."airline_id", f0."departure", f0."arrival", f0."alternate", f0."user_id", f0."plane_id" FROM "flights" AS f0 WHERE (f0."airline_id"::uuid = $1::uuid) ["8f251331-d27b-4d42-a05b-5dbe3e019ebe"]
I only see a check for the tenant here (airline_id) and not the id of the flight. Am I missing something super obvious in my resource or is this a bug? Thanks a lot it in advance! 😀
5 replies
AEAsh Elixir
Created by richaard0 on 5/14/2023 in #support
ResourceValidations error
I just updated a bunch of deps and something that worked fine before just doesn't right now. I have the following error:
** (EXIT from #PID<0.104.0>) an exception was raised:
** (RuntimeError) Resource `Vigil.Operations.Airline` in relationship `:airline` is not accepted by api `Vigil.Accounts`. Please do one of the following...
** (EXIT from #PID<0.104.0>) an exception was raised:
** (RuntimeError) Resource `Vigil.Operations.Airline` in relationship `:airline` is not accepted by api `Vigil.Accounts`. Please do one of the following...
On my User resource, I have the following relationship:
relationships do
belongs_to :airline, Vigil.Operations.Airline do
api Vigil.Operations
allow_nil? false
end
end
relationships do
belongs_to :airline, Vigil.Operations.Airline do
api Vigil.Operations
allow_nil? false
end
end
It was my understanding that it should be fine if I specify which api this belongs to, am I missing something?
8 replies
AEAsh Elixir
Created by richaard0 on 4/23/2023 in #support
Load relationships on inserted ressource
I was wondering if there was a way to load relationships by default on an inserted ressource after a successful submit of a for_create form? The goal here is to simply append that newly inserted ressource to a list afterwards, but I need some relationships to be loaded on that ressource. I know I can do it manually, but I was wondering if there was a way to define some defaults "load" somewhere? Thanks a lot in advance 🙂
6 replies
AEAsh Elixir
Created by richaard0 on 3/30/2023 in #support
AshPhoenix potential bug with relationships
I have the following form:
<.simple_form
:let={f}
for={@form}
id="add-flight-form"
phx-submit="submit"
phx-change="validate"
>
<.input
field={{f, :plane}}
type="select"
label="Airplane"
options={Enum.map(@fleet, & &1.registration)}
/>
<.input field={{f, :number}} label="Number" />
<.input field={{f, :departure}} label="Departure" />
<.input field={{f, :arrival}} label="Arrival" />
<.input field={{f, :alternate}} label="Alternate" />
<:actions>
<.button>Save</.button>
</:actions>
</.simple_form>
<.simple_form
:let={f}
for={@form}
id="add-flight-form"
phx-submit="submit"
phx-change="validate"
>
<.input
field={{f, :plane}}
type="select"
label="Airplane"
options={Enum.map(@fleet, & &1.registration)}
/>
<.input field={{f, :number}} label="Number" />
<.input field={{f, :departure}} label="Departure" />
<.input field={{f, :arrival}} label="Arrival" />
<.input field={{f, :alternate}} label="Alternate" />
<:actions>
<.button>Save</.button>
</:actions>
</.simple_form>
I do get an error if the number or plane field is missing, but I don't have any errors for the departure, arrival and alternate fields. All 3 of these fields have a similar relationship on my resource that looks like this:
belongs_to :departure_airport, Vigil.Airports.Airport do
api Vigil.Airports
attribute_writable? true
allow_nil? false
source_attribute :departure
destination_attribute :icao_code
attribute_type :string
end
belongs_to :departure_airport, Vigil.Airports.Airport do
api Vigil.Airports
attribute_writable? true
allow_nil? false
source_attribute :departure
destination_attribute :icao_code
attribute_type :string
end
If I inspect the form, I don't see any errors at all regarding those fields, as if they weren't attributes at all, but I do see the attributes data: attributes: %{alternate: nil, arrival: nil, departure: nil, number: nil}, Shouldn't the form show errors about those fields being required?
14 replies
AEAsh Elixir
Created by richaard0 on 3/21/2023 in #support
Multitenancy and no_attributes? relationship option
Reading through the docs, I encountered the part about the no_attributes? option while declaring relationships.
Specifically, if you have a tenant resource like Organization , you can use no_attributes? to do things like has_many :employees, Employee, no_attributes?: true , which lets you avoid having an unnecessary organization_id field on Employee
Specifically, if you have a tenant resource like Organization , you can use no_attributes? to do things like has_many :employees, Employee, no_attributes?: true , which lets you avoid having an unnecessary organization_id field on Employee
Reading this, I was under the impression that I wouldn't have to specify a belong_to on my resource, but I encounter this error if I don't define one:
** (EXIT from #PID<0.93.0>) an exception was raised:
** (Spark.Error.DslError) [Vigil.Fleet.Plane]
multitenancy -> attribute:
Attribute airline_id used in multitenancy configuration does not exist
** (EXIT from #PID<0.93.0>) an exception was raised:
** (Spark.Error.DslError) [Vigil.Fleet.Plane]
multitenancy -> attribute:
Attribute airline_id used in multitenancy configuration does not exist
Am I missing something or do I still need to define a belong_to for my Plane resource? For reference, my airline resource has the following:
has_many :planes, Vigil.Fleet.Plane do
api Vigil.Fleet
no_attributes? true
end
has_many :planes, Vigil.Fleet.Plane do
api Vigil.Fleet
no_attributes? true
end
7 replies
AEAsh Elixir
Created by richaard0 on 3/13/2023 in #support
Multitenancy and different Liveviews
So this might not be directly related to AshAuthentication, but somebody could help me figure out what's going. I'm still super new to Elixir and Phoenix so bear with me haha Continuing from the discussion above with multitenancy I have a live_view being rendered normally from the router, but this one also has a child live_view rendered with live_render like so:
<%= live_render(@socket, MyAppWeb.Messaging,
id: "messaging",
sticky: true
) %>
<div class="flex flex-grow flex-col">
<.live_component
module={MyAppWeb.Components.AppHeader}
id="header"
page_title={@page_title}
current_user={@current_user}
/>
<div class="p-2">
<p class="text-2xl">Component here</p>
</div>
</div>
<%= live_render(@socket, MyAppWeb.Messaging,
id: "messaging",
sticky: true
) %>
<div class="flex flex-grow flex-col">
<.live_component
module={MyAppWeb.Components.AppHeader}
id="header"
page_title={@page_title}
current_user={@current_user}
/>
<div class="p-2">
<p class="text-2xl">Component here</p>
</div>
</div>
When I log in, I automatically gets logged out. When I inspect the socket and session of the messaging live_view, on the second render, there aren't any users or tenant. In messaging.ex, I have the following: on_mount {MyAppWeb.UserAuth, :current_user} which points to the following:
def on_mount(:current_user, _params, _session, socket) do
{:cont, Phoenix.Component.assign_new(socket, :current_user, &get_tenant/1)}
end
def on_mount(:current_user, _params, _session, socket) do
{:cont, Phoenix.Component.assign_new(socket, :current_user, &get_tenant/1)}
end
Is there anything I'm missing? If I comment out the multitenancy part out, I don't encounter the isssue, same thing if I comment out the messaging live view
117 replies