Fix misleading disambiguation error where relationship looks like valid syntax

* Add columns for the m2m relationship
This commit is contained in:
Laurence Isla
2022-04-12 00:02:19 +02:00
committed by GitHub
parent 007f49a8bc
commit 7589102c6c
5 changed files with 48 additions and 16 deletions
@@ -20,12 +20,12 @@ spec =
"details": [
{
"cardinality": "many-to-one",
"relationship": "message_sender_fkey[sender][id]",
"relationship": "message_sender_fkey using message(sender) and person(id)",
"embedding": "message with person"
},
{
"cardinality": "many-to-one",
"relationship": "message_sender_fkey[sender][id]",
"relationship": "message_sender_fkey using message(sender) and person_detail(id)",
"embedding": "message with person_detail"
}
],
@@ -38,6 +38,31 @@ spec =
, matchHeaders = [matchContentTypeJson]
}
it "errs when there's a table and view that point to the same fk (composite pk)" $
get "/activities?select=fst_shift(*)" `shouldRespondWith`
[json|
{
"details": [
{
"cardinality": "one-to-many",
"relationship": "fst_shift using activities(id, schedule_id) and unit_workdays(fst_shift_activity_id, fst_shift_schedule_id)",
"embedding": "activities with unit_workdays"
},
{
"cardinality": "one-to-many",
"relationship": "fst_shift using activities(id, schedule_id) and unit_workdays_fst_shift(fst_shift_activity_id, fst_shift_schedule_id)",
"embedding": "activities with unit_workdays_fst_shift"
}
],
"hint": "Try changing 'fst_shift' to one of the following: 'unit_workdays!fst_shift', 'unit_workdays_fst_shift!fst_shift'. Find the desired relationship in the 'details' key.",
"message": "Could not embed because more than one relationship was found for 'activities' and 'fst_shift'",
"code": "PGRST201"
}
|]
{ matchStatus = 300
, matchHeaders = [matchContentTypeJson]
}
it "errs when there are o2m and m2m cardinalities to the target table" $
get "/sites?select=*,big_projects(*)" `shouldRespondWith`
[json|
@@ -45,17 +70,17 @@ spec =
"details": [
{
"cardinality": "many-to-one",
"relationship": "main_project[main_project_id][big_project_id]",
"relationship": "main_project using sites(main_project_id) and big_projects(big_project_id)",
"embedding": "sites with big_projects"
},
{
"cardinality": "many-to-many",
"relationship": "test.jobs[jobs_site_id_fkey][jobs_big_project_id_fkey]",
"relationship": "jobs using jobs_site_id_fkey(site_id) and jobs_big_project_id_fkey(big_project_id)",
"embedding": "sites with big_projects"
},
{
"cardinality": "many-to-many",
"relationship": "test.main_jobs[jobs_site_id_fkey][jobs_big_project_id_fkey]",
"relationship": "main_jobs using jobs_site_id_fkey(site_id) and jobs_big_project_id_fkey(big_project_id)",
"embedding": "sites with big_projects"
}
],
@@ -75,12 +100,12 @@ spec =
"details": [
{
"cardinality": "many-to-one",
"relationship": "agents_department_id_fkey[department_id][id]",
"relationship": "agents_department_id_fkey using agents(department_id) and departments(id)",
"embedding": "agents with departments"
},
{
"cardinality": "one-to-many",
"relationship": "departments_head_id_fkey[id][head_id]",
"relationship": "departments_head_id_fkey using agents(id) and departments(head_id)",
"embedding": "agents with departments"
}
],
@@ -103,22 +128,22 @@ spec =
"details": [
{
"cardinality": "many-to-many",
"relationship": "test.whatev_jobs[whatev_jobs_site_id_1_fkey][whatev_jobs_project_id_1_fkey]",
"relationship": "whatev_jobs using whatev_jobs_site_id_1_fkey(site_id_1) and whatev_jobs_project_id_1_fkey(project_id_1)",
"embedding": "whatev_sites with whatev_projects"
},
{
"cardinality": "many-to-many",
"relationship": "test.whatev_jobs[whatev_jobs_site_id_1_fkey][whatev_jobs_project_id_2_fkey]",
"relationship": "whatev_jobs using whatev_jobs_site_id_1_fkey(site_id_1) and whatev_jobs_project_id_2_fkey(project_id_2)",
"embedding": "whatev_sites with whatev_projects"
},
{
"cardinality": "many-to-many",
"relationship": "test.whatev_jobs[whatev_jobs_site_id_2_fkey][whatev_jobs_project_id_1_fkey]",
"relationship": "whatev_jobs using whatev_jobs_site_id_2_fkey(site_id_2) and whatev_jobs_project_id_1_fkey(project_id_1)",
"embedding": "whatev_sites with whatev_projects"
},
{
"cardinality": "many-to-many",
"relationship": "test.whatev_jobs[whatev_jobs_site_id_2_fkey][whatev_jobs_project_id_2_fkey]",
"relationship": "whatev_jobs using whatev_jobs_site_id_2_fkey(site_id_2) and whatev_jobs_project_id_2_fkey(project_id_2)",
"embedding": "whatev_sites with whatev_projects"
}
],