Results 1 to 3 of 3

Thread: QSqlRelationalTableModel

  1. #1
    Join Date
    Nov 2008
    Location
    Croatia
    Posts
    4
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default QSqlRelationalTableModel

    is it posible to use QSqlRelationalTableModel to relate one column in source table to multiple columns in destination table? For instance, if inf first table you have:
    Qt Code:
    1. ID | NAME | AGE
    2. 1 | John | 10
    To copy to clipboard, switch view to plain text mode 

    and second:
    Qt Code:
    1. ID | MOTHER | FATHER
    2. 1 | Anne | Bob
    To copy to clipboard, switch view to plain text mode 

    to get the table:
    Qt Code:
    1. ID | NAME | AGE | MOTHER | FATHER
    2. 1 | John | 10 | Anne | Bob
    To copy to clipboard, switch view to plain text mode 

    model->setRelation replaces the column, while i'd like to add them.

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

    Default Re: QSqlRelationalTableModel

    The first question is whether the design of your database is correct. You could safely merge those two tables into a single one. As for the relational table model, it can't do what you want. You could implement a proxy that would merge two tables or create a view in your database and use QSqlTableModel or use QSqlQueryModel to fetch both tables. Just remember the latter is read-only.

  3. The following user says thank you to wysota for this useful post:

    marvin (19th November 2008)

  4. #3
    Join Date
    Nov 2008
    Location
    Croatia
    Posts
    4
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QSqlRelationalTableModel

    Quote Originally Posted by wysota View Post
    The first question is whether the design of your database is correct. You could safely merge those two tables into a single one. As for the relational table model, it can't do what you want. You could implement a proxy that would merge two tables or create a view in your database and use QSqlTableModel or use QSqlQueryModel to fetch both tables. Just remember the latter is read-only.
    tnx, i can't merge the tables, those were just for example, but using QSqlQueryModel solved my problem

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.