Results 1 to 4 of 4

Thread: QSqlRelationalTableModel & Left Join

  1. #1
    Join Date
    Nov 2009
    Posts
    15

    Default QSqlRelationalTableModel & Left Join

    Hello.

    completes the internal query as "inner join" so when we have a relation that has null values in the main table key the relation is not shown.

    I have valued three ways to avoiding this limitation:

    1 .- Fill null values with a special value that has an interrelation in the other table. Id zero value or something like that.
    2.- Sub-classing QSqlRelationalTableModel.
    3.- Direct modify qsqlrelationaltablemodel.cpp and qsqlrelationaltablemodel.h and add a function for select de join mode.

    Is there any way simpler to do this in editable data models?

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 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 & Left Join

    What would you like to show instead of null values in the rows that contain them? A NULL value in a field that is a foreign key can be considered a design flaw of the database. If you want to have null values as foreign key then don't pretend this is a relation and use QSqlTableModel() with a custom delegate that will treat the foreign key in a special manner - by replacing its values with ones from another 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
    Sep 2009
    Location
    Tashkent, Uzbekistan
    Posts
    107
    Thanks
    1
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QSqlRelationalTableModel & Left Join

    Actually Wysota is right because foreign key in one table is a primary key in another. But there are some situations when you need to fill the tables and you have cross relations between 2 tables (not the best solution anyway). For that case you can solve it with sql statements. You event don't need any Qt for this.

  4. #4
    Join Date
    Nov 2009
    Posts
    15

    Default Re: QSqlRelationalTableModel & Left Join

    Quote Originally Posted by wysota View Post
    What would you like to show instead of null values in the rows that contain them? A NULL value in a field that is a foreign key can be considered a design flaw of the database. If you want to have null values as foreign key then don't pretend this is a relation and use QSqlTableModel() with a custom delegate that will treat the foreign key in a special manner - by replacing its values with ones from another table.
    I would not like to show nothing different from NULL values but I want these NULL values if they are in some record/row.
    I am not in accordance with your affirmation. I can have a relation between two tables and I can have NULL values in a foreign key when certain records do not need to have this relation. What is the problem with this? Another thing is that I have a value that replaces the NULL (with zero, null string and so on...) and assign it when the user has not a choice but why am I going to do that if I have a LEFT JOIN that has this work for me?

    A small example: I have a table of books that has a field for "main author" and another for "additional authors". I have a table with Authors that has a relation with the books table. "main author" and "additional authors" are foreign keys that point to Authors table. There are books that have "additional authors" and there are another that only have an author. Why must I fill a record for the first case? I want display the record and I want a NULL value in the field. QSqlRelationalTableModel does not allow it. It only displays the records with an INNER join select but What about OUTER join?.

    Thank you very much and sorry for my use of the english language
    Last edited by mhbeyle; 21st December 2009 at 12:44.

Similar Threads

  1. Window Title Text left alignment issue.
    By kaushal_gaurav in forum Qt Programming
    Replies: 2
    Last Post: 3rd March 2010, 14:46
  2. combining Alt + Left Mouse Button
    By speedracer in forum Qt Programming
    Replies: 1
    Last Post: 3rd June 2009, 13:29
  3. QTreeView/QHeaderView : resize handle on the left
    By Jeremy in forum Qt Programming
    Replies: 3
    Last Post: 14th May 2009, 22:43
  4. dummy question(Error)
    By Masih in forum Qt Programming
    Replies: 12
    Last Post: 19th July 2007, 23:38
  5. left and right margins in QPrinter
    By igor_x in forum Newbie
    Replies: 0
    Last Post: 2nd November 2006, 10:42

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.