Results 1 to 5 of 5

Thread: QSqlRelationalTableModel Many to Many relation

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

    Default QSqlRelationalTableModel Many to Many relation

    Hi everyone,

    The goal is to build a simple recipe ingredients app using pyqt.

    I have three tables. The first table stores the recipes. The second table stores the ingredients. The third table stores the recipe ingredient join table.

    QSqlRelationalTableModel setRelation states that the table's primary key may not contain a relation to another table. How do you handle a many to many relationship using pyqt then?

    My original thought was I was going to have three QSqlRelationalTableModel to handle this.

    Does this mean you cannot use QSqlRelationalDelegate and would have to create a custom delegate to handle the relationship? I did see this thread http://www.qtcentre.org/threads/4658...iting-probllem.

    Thank you,
    Luke Kaim

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,364
    Thanks
    3
    Thanked 5,013 Times in 4,791 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QSqlRelationalTableModel Many to Many relation

    Quote Originally Posted by lukeQt View Post
    How do you handle a many to many relationship using pyqt then?
    Add a column that will be the primary key of the join table.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


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

    Default Re: QSqlRelationalTableModel Many to Many relation

    I have an additional question though. How does PyQt handle compound/composite keys though? If I only have one primary key, then there is nothing stopping the user from adding eggs twice to the same recipe. Does pyqt support this? If pyqt does not support this, which I suspect that it doesn't, then what workarounds do people use? Can you use a unique index to handle this? Thank you Wysota for responding.

    Luke Kaim
    Last edited by lukeQt; 31st March 2015 at 18:13.

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,364
    Thanks
    3
    Thanked 5,013 Times in 4,791 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QSqlRelationalTableModel Many to Many relation

    Quote Originally Posted by lukeQt View Post
    If I only have one primary key
    You always have one primary key. Remaining keys are secondary keys.

    then there is nothing stopping the user from adding eggs twice to the same recipe.
    No, because you can set a unique index on a pair of columns which are foreign keys from the tables you are linking.
    Does pyqt support this?
    PyQt has nothing to do with this. This is a feature of the database you are using. Qt is just a wrapper over the native client library for your dbms.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


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

    Default Re: QSqlRelationalTableModel Many to Many relation

    Thank you wysota. That is the way that I thought you could do it.

    Luke

Similar Threads

  1. Replies: 4
    Last Post: 2nd January 2013, 14:37
  2. Multiple axes with a relation
    By pkj in forum Qwt
    Replies: 1
    Last Post: 21st February 2011, 07:46
  3. Replies: 1
    Last Post: 18th March 2009, 22:26
  4. QComboBox QSqlQueryModel & relation.
    By matheww in forum Qt Programming
    Replies: 2
    Last Post: 20th June 2007, 05:56
  5. Is there a relation between Qt and Quick Time?
    By Mariane in forum General Discussion
    Replies: 18
    Last Post: 24th January 2006, 22:23

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.