django orm – how to join multiple tables

I have a bunch of tables in postgresql:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<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.

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<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:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<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?

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật