polymorphic_on_delete option needs refining and potentially moving
I maintainer di solito rispondono entro 1 giorno
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 5/5
- Tempo stimato
- Più di una settimana
- Idoneità per principianti
- 25/100
Direzione di ricerca
Inizia riproducendo l’esempio con la configurazione references e polymorphic_on_delete :delete su entrambi i lati della relazione. Esamina la migration generata e confronta il comportamento di eliminazione delle chiavi esterne. Il lavoro è completo quando è stata concordata una posizione per la configurazione oppure una progettazione a livello di relazione che gestisca correttamente più relazioni polimorfiche.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Describe the bug
The references config block containing a polymorphic_on_delete :delete setting is on the "unexpected" side of the relationship between a resource and a polymorphic resource. If it is set on the polymorphic resource side, the generated migration does not implement the delete in the foreign key constraint.
Discussion here
https://elixirforum.com/t/how-to-combine-polymorphic-with-references-on-delete/60756
To Reproduce
defmodule MyApp.Location do
use Ash.Resource, data_layer: AshPostgres.DataLayer
postgres do
repo MyApp.Repo
polymorphic? true
# HAS NO EFFECT
references do
polymorphic_on_delete :delete
end
end
attributes do
uuid_primary_key :id
attribute :resource_id, :uuid do
allow_nil? false
private? true
end
attribute :x, :float
attribute :y, :float
end
end
defmodule MyApp.Event do
use Ash.Resource, data_layer: AshPostgres.DataLayer
postgres do
repo MyApp.Repo
table "events"
# WORKS IF IT IS HERE
references do
polymorphic_on_delete :delete
end
end
attributes do
uuid_primary_key :id
attribute :when, :utc_datetime, allow_nil?: false, default: &DateTime.utc_now/0
attribute :what, :string
attribute :who, :string
end
relationships do
has_one :location, Location do
relationship_context %{data_layer: %{table: "event_locations"}}
destination_attribute :resource_id
end
end
Expected behavior
To be agreed. Currently the config location is surprising as for other relationships it is the "owned" resource that defines the on_delete behaviour rather than the owning resource. However, where you have multiple relationships to polymorphic resources (to be expected!) and want to control the delete behaviour for each separately it may make sense to do it this way round. So there's a philosophical question to answer first - should the delete behaviour belong to the polymorphic resource or to the relationship? If it is the relationship it should probably be defined at the specific relationship level.
In the example above, this may be something like:
defmodule MyApp.Event do
use Ash.Resource, data_layer: AshPostgres.DataLayer
postgres do
repo MyApp.Repo
table "events"
references do
# Either something here that points to the Location resource, but looks different to
# the existing config for relationships as it is inverted...
end
end
attributes do
uuid_primary_key :id
attribute :when, :utc_datetime, allow_nil?: false, default: &DateTime.utc_now/0
attribute :what, :string
attribute :who, :string
end
relationships do
has_one :location, Location do
# Or probably better here to collect together all the implementation details of the relationship in one place
relationship_context %{data_layer: %{table: "event_locations"}, on_delete: :delete}
destination_attribute :resource_id
end
end
**Runtime
- Elixir version: 1.15.4
- Erlang version: Erlang/OTP 26 [erts-14.0.2]
- OS: Mac
- Ash version: 2.17.17
- Ash Postgres: 1.3.61
- any related extension versions
- Lingua principale
- Elixir
- Stelle
- 191
- Fork
- 186
- Merge medio
- 16h 4m
- PR unite (30g)
- 17
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Nessun modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di ash-project/ash_postgres
-
Temporal: an update or destroy as of an instant doesn't carry into later versionsForse già presa @hoanle0126 l’ha presa 14 giorni fa. Aperta
Difficoltà 5/5 Più di una settimana Idoneità per principianti 15/100
ash-project/ash_postgres#915 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
has_create_action?/1 excludes manual creates, making the #49 nullability fix inert on AshEvents resourcesForse di nuovo libera @Mckay-Hinds l’ha presa 19 giorni fa e non c’è nessuna pull request aperta. Aperta
Difficoltà 3/5 1-2 giorni Idoneità per principianti 76/100
ash-project/ash_postgres#851 · 9 commenti ·
I maintainer di solito rispondono entro 1 giorno
-
enhancement
Difficoltà 4/5 3-5 giorni Idoneità per principianti 35/100
ash-project/ash_postgres#650 · 6 commenti ·
I maintainer di solito rispondono entro 1 giorno
-
bug
Difficoltà 4/5 3-5 giorni Idoneità per principianti 35/100
ash-project/ash_postgres#642 · 5 commenti ·
I maintainer di solito rispondono entro 1 giorno
-
enhancement
Difficoltà 5/5 Più di una settimana Idoneità per principianti 40/100
ash-project/ash_postgres#628 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di ash-project/ash_postgres
Issue simili
-
Flaky testApertadette technique
Difficoltà 2/5 1-3 ore Idoneità per principianti 65/100
etalab/transport-site#5701 ·
I maintainer di solito rispondono entro 5 giorni
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
I maintainer di solito rispondono entro 1 giorno
-
@swmansion/popcorn: published .d.ts files lack extensions on relative imports, breaking moduleResolution node16/nodenextForse già presa @Huyvux12 l’ha presa 1 giorno fa. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
software-mansion/popcorn#929 · 2 commenti ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
intellij-elixir/intellij-elixir#4705 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 85/100
phoenixframework/phoenix#6908 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno