polymorphic_on_delete option needs refining and potentially moving
Maintainer thường phản hồi trong vòng 1 ngày
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 5/5
- Thời gian dự kiến
- Hơn một tuần
- Mức phù hợp với người mới
- 25/100
Hướng nghiên cứu
Bắt đầu bằng cách tái hiện ví dụ với cấu hình references và polymorphic_on_delete :delete ở mỗi phía của quan hệ. Kiểm tra migration được tạo ra và so sánh hành vi xóa của các khóa ngoại. Công việc được xem là hoàn tất khi có một vị trí cấu hình đã được thống nhất hoặc một thiết kế ở cấp quan hệ xử lý chính xác nhiều quan hệ đa hình.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
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
- Ngôn ngữ chính
- Elixir
- Star
- 191
- Fork
- 186
- Merge trung bình
- 16 giờ 4 phút
- Pull request đã merge (30 ngày)
- 17
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Không có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của ash-project/ash_postgres
-
Temporal: an update or destroy as of an instant doesn't carry into later versionsCó thể đã có người làm @hoanle0126 đã nhận 14 ngày trước. Đang mở
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 15/100
ash-project/ash_postgres#915 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
has_create_action?/1 excludes manual creates, making the #49 nullability fix inert on AshEvents resourcesCó thể làm lại được @Mckay-Hinds đã nhận 19 ngày trước và không có pull request nào đang mở. Đang mở
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 76/100
ash-project/ash_postgres#851 · 9 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
enhancement
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 35/100
ash-project/ash_postgres#650 · 6 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
bug
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 35/100
ash-project/ash_postgres#642 · 5 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
enhancement
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 40/100
ash-project/ash_postgres#628 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của ash-project/ash_postgres
Issue tương tự
-
Flaky testĐang mởdette technique
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 65/100
etalab/transport-site#5701 ·
Maintainer thường phản hồi trong vòng 5 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
Maintainer thường phản hồi trong vòng 1 ngày
-
@swmansion/popcorn: published .d.ts files lack extensions on relative imports, breaking moduleResolution node16/nodenextCó thể đã có người làm @Huyvux12 đã nhận 1 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
software-mansion/popcorn#929 · 2 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
intellij-elixir/intellij-elixir#4705 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 85/100
phoenixframework/phoenix#6908 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày