Test calling setRelation() with QSqlRelation() clears the relation
Change-Id: I93dbec54bfb9402b9044323862c2ae1d41e1790a Reviewed-by: Jesus Fernandez <Jesus.Fernandez@qt.io>
This commit is contained in:
parent
9b361f0e90
commit
fa1397882a
@ -77,6 +77,7 @@ private slots:
|
|||||||
void psqlSchemaTest();
|
void psqlSchemaTest();
|
||||||
void selectAfterUpdate();
|
void selectAfterUpdate();
|
||||||
void relationOnFirstColumn();
|
void relationOnFirstColumn();
|
||||||
|
void setRelation();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void dropTestTables( QSqlDatabase db );
|
void dropTestTables( QSqlDatabase db );
|
||||||
@ -1550,5 +1551,27 @@ void tst_QSqlRelationalTableModel::relationOnFirstColumn()
|
|||||||
tst_Databases::safeDropTables(db, QStringList() << testTable1 << testTable2);
|
tst_Databases::safeDropTables(db, QStringList() << testTable1 << testTable2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void tst_QSqlRelationalTableModel::setRelation()
|
||||||
|
{
|
||||||
|
QFETCH_GLOBAL(QString, dbName);
|
||||||
|
QSqlDatabase db = QSqlDatabase::database(dbName);
|
||||||
|
CHECK_DATABASE(db);
|
||||||
|
recreateTestTables(db);
|
||||||
|
|
||||||
|
QSqlRelationalTableModel model(0, db);
|
||||||
|
model.setTable(reltest1);
|
||||||
|
QVERIFY_SQL(model, select());
|
||||||
|
QCOMPARE(model.data(model.index(0, 2)), QVariant(1));
|
||||||
|
|
||||||
|
model.setRelation(2, QSqlRelation(reltest2, "id", "title"));
|
||||||
|
QVERIFY_SQL(model, select());
|
||||||
|
QCOMPARE(model.data(model.index(0, 2)), QVariant("herr"));
|
||||||
|
|
||||||
|
// Check that setting an invalid QSqlRelation() clears the relation
|
||||||
|
model.setRelation(2, QSqlRelation());
|
||||||
|
QVERIFY_SQL(model, select());
|
||||||
|
QCOMPARE(model.data(model.index(0, 2)), QVariant(1));
|
||||||
|
}
|
||||||
|
|
||||||
QTEST_MAIN(tst_QSqlRelationalTableModel)
|
QTEST_MAIN(tst_QSqlRelationalTableModel)
|
||||||
#include "tst_qsqlrelationaltablemodel.moc"
|
#include "tst_qsqlrelationaltablemodel.moc"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user