polymorphic_on_delete option needs refining and potentially moving
メンテナーはふだん 1 日以内に返信
まだ誰も着手していません。
評価
- 難易度
- 5/5
- 見積もり時間
- 1週間以上
- 初心者へのやさしさ
- 25/100
調査の方向性
まず、リレーションの各側で references 設定と polymorphic_on_delete :delete を使用して例を再現します。生成されたマイグレーションを調べ、外部キーの削除動作を比較します。複数のポリモーフィックなリレーションを正しく処理する、合意された設定の配置場所またはリレーションレベルの設計ができれば完了です。
索引モデルが issue の本文から書いたものです。
説明
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
- 主要言語
- Elixir
- スター
- 191
- フォーク
- 186
- 平均マージ
- 16時間 4分
- マージ済み PR(30日)
- 17
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートなし
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
ash-project/ash_postgres のほかの issue
-
Temporal: an update or destroy as of an instant doesn't carry into later versions対応中かも @hoanle0126 が 14 日前に担当しました。 オープン
難易度 5/5 1週間以上 初心者へのやさしさ 15/100
ash-project/ash_postgres#915 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
has_create_action?/1 excludes manual creates, making the #49 nullability fix inert on AshEvents resources再び着手できるかも @Mckay-Hinds が 19 日前に担当しましたが、オープン中のプルリクエストはありません。 オープン
難易度 3/5 1〜2日 初心者へのやさしさ 76/100
ash-project/ash_postgres#851 · コメント 9 件 ·
メンテナーはふだん 1 日以内に返信
-
enhancement
難易度 4/5 3〜5日 初心者へのやさしさ 35/100
ash-project/ash_postgres#650 · コメント 6 件 ·
メンテナーはふだん 1 日以内に返信
-
bug
難易度 4/5 3〜5日 初心者へのやさしさ 35/100
ash-project/ash_postgres#642 · コメント 5 件 ·
メンテナーはふだん 1 日以内に返信
-
enhancement
難易度 5/5 1週間以上 初心者へのやさしさ 40/100
ash-project/ash_postgres#628 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
ash-project/ash_postgres の issue をすべて見る
似ている issue
-
Flaky testオープンdette technique
難易度 2/5 1〜3時間 初心者へのやさしさ 65/100
etalab/transport-site#5701 ·
メンテナーはふだん 5 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
メンテナーはふだん 1 日以内に返信
-
@swmansion/popcorn: published .d.ts files lack extensions on relative imports, breaking moduleResolution node16/nodenext対応中かも @Huyvux12 が 1 日前に担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
software-mansion/popcorn#929 · コメント 2 件 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
intellij-elixir/intellij-elixir#4705 ·
メンテナーはふだん 1 日以内に返信
-
難易度 1/5 1時間未満 初心者へのやさしさ 85/100
phoenixframework/phoenix#6908 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信