Results 1 to 1 of 1

Thread: PyQt SQL Many to Many relationship question

  1. #1
    Join Date
    Oct 2014
    Posts
    22
    Qt products
    Qt3 Qt4 Qt5 PyQt3 PyQt4

    Default PyQt SQL Many to Many relationship question

    Hi Everyone,

    Is it possible to have joins in an sqlrelationaltablemodel? How do you do joins and show the data? I suspect that this is not possible, but wanted to check. I am using a sqlrelationaltablemodel. How can you do joins and add that to the model?

    In pure sql I can do this:
    SELECT * FROM rt_table_has_mgmt_desc
    INNER JOIN rt_table on rt_table_has_mgmt_desc.rt_table_id = rt_table.id
    INNER JOIN mgmt_desc ON mgmt_desc.id = rt_table_has_mgmt_desc.mgmt_desc_id
    INNER JOIN mgmt_desc_lu ON mgmt_desc_lu.id = mgmt_desc.mgmt_lu_id;

    How do I do this in a model in PyQt? I suspect you can't, but what is the work around here?
    What I want is this:

    2 1 77 blm 2000-01-01 2000-01-01 2000-01-01 Limited
    3 1 78 blm 2000-01-01 2000-01-01 2000-01-01 Closed
    4 1 79 blm 2000-01-01 2000-01-01 2000-01-01 Open
    5 1 80 blm 2000-01-01 2000-01-01 2000-01-01 Limited
    6 6 81 blm 2000-01-01 2000-01-01 2000-01-01 Open
    7 10 82 blm 2000-01-01 2000-01-01 2000-01-01 Limited
    8 11 83 blm 2000-01-01 2000-01-01 2000-01-01 Closed

    my db schema is:
    CREATE TABLE rt_table_has_mgmt_desc (
    id INTEGER PRIMARY KEY,
    rt_table_id INTEGER NOT NULL,
    mgmt_desc_id INTEGER NOT NULL,
    CONSTRAINT 'fk_rt_table_has_mgmt_desc_rt_table1' FOREIGN KEY ( rt_table_id ) REFERENCES rt_table ( id ) ON DELETE NO ACTION
    ON UPDATE NO ACTION,
    CONSTRAINT 'fk_rt_table_has_mgmt_desc_mgmt_desc1' FOREIGN KEY ( mgmt_desc_id ) REFERENCES mgmt_desc ( id )
    );

    CREATE TABLE mgmt_desc (
    id INTEGER PRIMARY KEY AUTOINCREMENT,
    entry_date TEXT NOT NULL,
    start_date TEXT NOT NULL,
    End_date TEXT,
    mgmt_lu_id INTEGER NOT NULL,
    CONSTRAINT 'fk_mgmt_lu_mgmt_lu_id' FOREIGN KEY ( mgmt_lu_id ) REFERENCES mgmt_desc_lu ( id ) ON DELETE NO ACTION
    ON UPDATE NO ACTION
    );

    CREATE TABLE mgmt_desc_lu (
    id INTEGER PRIMARY KEY,
    mgmt_name TEXT NOT NULL,
    mgmt_alias TEXT NOT NULL,
    mgmt_def TEXT NOT NULL
    );
    Last edited by lukeQt; 13th August 2015 at 22:43.

Similar Threads

  1. Replies: 0
    Last Post: 29th January 2015, 11:55
  2. Replies: 5
    Last Post: 25th January 2015, 18:36
  3. Replies: 0
    Last Post: 5th November 2009, 20:29
  4. QString::toStdString in PyQt Question
    By di_zou in forum Newbie
    Replies: 1
    Last Post: 2nd November 2009, 21:09
  5. Question about QCalendarWidget with PyQT
    By hf in forum Qt Programming
    Replies: 2
    Last Post: 21st April 2008, 23:40

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.