Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit6414bed

Browse files
committed
improvement: better error message on missing table
1 parentf1280d3 commit6414bed

File tree

1 file changed

+26
-7
lines changed

1 file changed

+26
-7
lines changed

‎lib/data_layer.ex‎

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -263,9 +263,16 @@ defmodule AshPostgres.DataLayer do
263263

264264
@impltrue
265265
defrun_query(query,resource)do
266-
{:ok,repo(resource).all(query,repo_opts(query))}
266+
ifAshPostgres.polymorphic?(resource)&&no_table?(query)do
267+
raise_table_error!(resource,:read)
268+
else
269+
{:ok,repo(resource).all(query,repo_opts(query))}
270+
end
267271
end
268272

273+
defpno_table?(%{from:%{source:{"",_}}}),do:true
274+
defpno_table?(_),do:false
275+
269276
defprepo_opts(%Ash.Changeset{tenant:tenant,resource:resource})do
270277
repo_opts(%{tenant:tenant,resource:resource})
271278
end
@@ -481,7 +488,7 @@ defmodule AshPostgres.DataLayer do
481488
defpecto_changeset(record,changeset,type)do
482489
ecto_changeset=
483490
record
484-
|>set_table(changeset)
491+
|>set_table(changeset,type)
485492
|>Ecto.Changeset.change(changeset.attributes)
486493

487494
casetypedo
@@ -506,17 +513,14 @@ defmodule AshPostgres.DataLayer do
506513
end
507514
end
508515

509-
defpset_table(record,changeset)do
516+
defpset_table(record,changeset,operation)do
510517
ifAshPostgres.polymorphic?(record.__struct__)do
511518
table=changeset.context[:data_layer][:table]||AshPostgres.table(record.__struct)
512519

513520
iftabledo
514521
Ecto.put_meta(record,source:table)
515522
else
516-
raise"""
517-
Attempted to change a polymorphic resource without setting the `table` context,
518-
and without a default table configured on the resource.
519-
"""
523+
raise_table_error!(changeset.resource,operation)
520524
end
521525
else
522526
record
@@ -1824,4 +1828,19 @@ defmodule AshPostgres.DataLayer do
18241828
defptable(resource,changeset)do
18251829
changeset.context[:data_layer][:table]||AshPostgres.table(resource)
18261830
end
1831+
1832+
defpraise_table_error!(resource,operation)do
1833+
ifAshPostgres.polymorphic?(resource)do
1834+
raise"""
1835+
Could not determine table for#{operation} on#{inspect(resource)}.
1836+
1837+
Polymorphic resources require that the `data_layer[:table]` context is provided.
1838+
See the guide on polymorphic resources for more information.
1839+
"""
1840+
else
1841+
raise"""
1842+
Could not determine table for#{operation} on#{inspect(resource)}.
1843+
"""
1844+
end
1845+
end
18271846
end

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp