I have a bunch of tables in postgresql:
<code>create TABLE run (
id integer NOT NULL,
build_id integer NOT NULL,
);
CREATE TABLE test_info (
suite_id integer NOT NULL,
run_id integer NOT NULL,
test_id integer NOT NULL,
id integer NOT NULL,
error_text text
);
CREATE TABLE tool_info (
id integer NOT NULL,
tool_id integer,
revision_id integer,
test_info_id integer,
);
CREATE TABLE suite_info (
id integer,
suite_id integer NOT NULL,
run_id integer NOT NULL,
);
CREATE TABLE test (
id integer NOT NULL,
path text NOT NULL
);
</code>
<code>create TABLE run (
id integer NOT NULL,
build_id integer NOT NULL,
);
CREATE TABLE test_info (
suite_id integer NOT NULL,
run_id integer NOT NULL,
test_id integer NOT NULL,
id integer NOT NULL,
error_text text
);
CREATE TABLE tool_info (
id integer NOT NULL,
tool_id integer,
revision_id integer,
test_info_id integer,
);
CREATE TABLE suite_info (
id integer,
suite_id integer NOT NULL,
run_id integer NOT NULL,
);
CREATE TABLE test (
id integer NOT NULL,
path text NOT NULL
);
</code>
create TABLE run (
id integer NOT NULL,
build_id integer NOT NULL,
);
CREATE TABLE test_info (
suite_id integer NOT NULL,
run_id integer NOT NULL,
test_id integer NOT NULL,
id integer NOT NULL,
error_text text
);
CREATE TABLE tool_info (
id integer NOT NULL,
tool_id integer,
revision_id integer,
test_info_id integer,
);
CREATE TABLE suite_info (
id integer,
suite_id integer NOT NULL,
run_id integer NOT NULL,
);
CREATE TABLE test (
id integer NOT NULL,
path text NOT NULL
);
I’d like to write the following query using the django ORM. I’m using 2.2.
<code>select test.path, tool_info.id, run.id, test_info.id, suite_info.id from run join test_info on run.id = test_info.run_id join suite_info on run.id = suite_info.run_id join tool_info on tool_info.test_info_id=test_info.id join test on test_info.test_id=test.id where run.id=34;
</code>
<code>select test.path, tool_info.id, run.id, test_info.id, suite_info.id from run join test_info on run.id = test_info.run_id join suite_info on run.id = suite_info.run_id join tool_info on tool_info.test_info_id=test_info.id join test on test_info.test_id=test.id where run.id=34;
</code>
select test.path, tool_info.id, run.id, test_info.id, suite_info.id from run join test_info on run.id = test_info.run_id join suite_info on run.id = suite_info.run_id join tool_info on tool_info.test_info_id=test_info.id join test on test_info.test_id=test.id where run.id=34;
I’ve tried this:
<code>x= Run.objects.filter(suiteinfo__run_id=34)
(Pdb) str(x.query)
'SELECT "run"."id", "run"."build_id", "run"."date", "run"."type_id", "run"."date_finished", "run"."ko_type", "run"."branch_id", "run"."arch_id" FROM "run" INNER JOIN "suite_info" ON ("run"."id" = "suite_info"."run_id") WHERE "suite_info"."run_id" = 34'
</code>
<code>x= Run.objects.filter(suiteinfo__run_id=34)
(Pdb) str(x.query)
'SELECT "run"."id", "run"."build_id", "run"."date", "run"."type_id", "run"."date_finished", "run"."ko_type", "run"."branch_id", "run"."arch_id" FROM "run" INNER JOIN "suite_info" ON ("run"."id" = "suite_info"."run_id") WHERE "suite_info"."run_id" = 34'
</code>
x= Run.objects.filter(suiteinfo__run_id=34)
(Pdb) str(x.query)
'SELECT "run"."id", "run"."build_id", "run"."date", "run"."type_id", "run"."date_finished", "run"."ko_type", "run"."branch_id", "run"."arch_id" FROM "run" INNER JOIN "suite_info" ON ("run"."id" = "suite_info"."run_id") WHERE "suite_info"."run_id" = 34'
I can see it is doing a join, but the data doesn’t appear in the select. I’ve tried selected_related, and the like.
the RUN table is the central table that ties the data together. How can I create that query using the ORM?