Results 1 to 6 of 6

Thread: QSqlRelationalTableModel & advanced relationships

  1. #1
    Join Date
    Mar 2009
    Posts
    72
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows
    Thanks
    7

    Default QSqlRelationalTableModel & advanced relationships

    Hi guys!

    I need to map database "many-to-many" and "one-to-many" relations into my Qt code. I didn't found an "official" Qt class for this feature so my question is: what's the best approach, in your opinion, for implementing a complete database-relationship support?

    My idea is to create two new classes:

    1) QSqlAdvancedRelation which inherits from QSqlRelation and maps all three main relation types ("one-to-one", "one-to-many", "many-to-many").

    2) QSqlAdvancedRelationalTableModel which inherits from QSqlRelationalTableModel and uses one or more instances of QSqlAdvancedRelation class.

    For many-to-many relation, the idea is to use the relation table name as a virtual field name in the original table which value is a list of QModelIndex of the related table and vice versa:

    Qt Code:
    1. Original table <- Relationship table -> Related table
    To copy to clipboard, switch view to plain text mode 

    For one-to-many relation, the approach is simpler: the relation returns the list of QModelIndex of the related model filtered by a where clause.

    Qt Code:
    1. Original table <- Related table
    To copy to clipboard, switch view to plain text mode 

    What do you think about this approach?

  2. #2
    Join Date
    Jun 2007
    Location
    Austria (Europe)
    Posts
    31
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    5

    Default Re: QSqlRelationalTableModel & advanced relationships

    I have the same problem...

  3. #3
    Join Date
    Mar 2009
    Posts
    72
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows
    Thanks
    7

    Default Re: QSqlRelationalTableModel & advanced relationships

    Well, what about to start a collaborative project to implement a better support for database mapping in Qt?
    Last edited by zuck; 4th August 2009 at 13:34.

  4. #4
    Join Date
    Jun 2007
    Location
    Austria (Europe)
    Posts
    31
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    5

    Default Re: QSqlRelationalTableModel & advanced relationships

    Too late - I've already finalized my own QSqlQuery subclass but in a way that is very specific to my needs.

  5. #5
    Join Date
    Mar 2009
    Posts
    72
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows
    Thanks
    7

    Default Re: QSqlRelationalTableModel & advanced relationships

    Ok Could you post any tips about your solution, please?

  6. #6
    Join Date
    Jun 2007
    Location
    Austria (Europe)
    Posts
    31
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    5

    Default Re: QSqlRelationalTableModel & advanced relationships


Similar Threads

  1. What's the relationship between signal/slot and event?
    By twosnowman in forum Qt Programming
    Replies: 4
    Last Post: 11th January 2006, 17:13

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
  •  
Qt is a trademark of The Qt Company.