Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Qt Sql Join question



  • Hi Everyone,

    Sorry if this question has been answered already. I believe there are more then one way to approach this problem. I have a database I have a table for cities and a table for country. This is a one to many relationship. I have country setup like this model->setRelation(3, QSqlRelation("country", "id", "name"));. That works wonderful. But I want to have another column in my model that is for city. I only want to return the cities that are in Germany and not all cites. Could I use a proxy model for this? Could I query the database and return all cities that are in Germany? Summerfield queries the database for this. Could you use a join? Could you overload the data and set data methods for QtSql.QSqlRelationalTableModel? I am looking for the least resistance method. I believe that there could be more then one way to solve this problem. I am unsure of the best way to approach this problem?

    Also what if there was a one to one relationship how would you do it in this case, because it doesn't make sense to have a combobox with only one value in it? Could you use set data method? How would that look?

    Thank you,
    Luke


Log in to reply