setRelation and NULL in ID
PROBLEM:
In a QTableView, if a row has a null value in a combo box field (that writes in the row the value of a foreign key), the user does not see the row (!).
MORE INFORMATION:
I need to have a form where the user enters information about something in a QTableView (for the sake of clarity, I have chosen an example of a database of poems).
Some poems would have author and others not; (the author would be the foreign key). if I try a code like this:
Code:
model.setTable("poems");
model.
setRelation(3,
QSqlRelation( "authors",
"author_id",
"name"));
model.setHeaderData(0, Qt::Horizontal, t("ID"));
model.setHeaderData(1, Qt::Horizontal, t("Title"));
model.setHeaderData(2, Qt::Horizontal, t("Year"));
model.setHeaderData(3, Qt::Horizontal, t("Author"));
model.select();
table_view->setModel(model);
Then the rows that are poems without an author... are not shown.:eek:
Re: setRelation and NULL in ID
The problem is that Qt uses inner join and you want to use outer join, so instead you can use QSqlTableModel (if you have a view) or QSqlQueryModel. In the latter case the model won't be editable and with view it depends on the underlying DBMS.
Re: setRelation and NULL in ID
I am also interested in this problem. But I dont understand the answer from jacek. Have someone solved this problem? Thanks.
Re: setRelation and NULL in ID
By now, I will use a record with identifier 0 and empty description in my tables.
See this too:
http://www.qtcentre.org/forum/f-qt-p...del-12784.html
Re: setRelation and NULL in ID
Hi,
I know this is an old thread, but you need to set the setJoinMode. By default the sqlRelationalTableModel uses an inner join. You need to set it to be a left join.
self.setJoinMode(QtSql.QSqlRelationalTableModel.Le ftJoin). This took me forever to figure out because the row would go into the database just not the view.
http://pyqt.sourceforge.net/Docs/PyQ...ml#setJoinMode