Is there a model-view example with a n : m relation?
I am searching a QtWidget example using model-view (delegate) technology to edit database items with a n : m relations.
An example would be n-persons can attend m-meetings.
A person can attend 0 to m meetings.
A meeting can be visited by 0 to n persons.
A sample how I implement a n : m relation in my database:
(The '*' shows the primary key colums).
I prefer C++ and QtWidgets for my desktop application. My application is a „fat client“ / „client-server-application“ with a MySQL database.
Hi and welcome to devnet,
How would you like to do the editing ? You can use e.g. QSqlRelationalTableModel and QTableView or QDataWidgetMapper.
Hope it helps
@SGaist I like to have two entry forms.
One master-detail form where I can create/edit/delete a person (master) and add 0..m meetings the person will attend (detail).
One master-detail form where I can create/edit/delete a meeting (master) and add 0..n persons which visit the meeting (detail).
Tree views could be helpfull too. One tree view could be persons as root elements and the meetings attached to them or a tree view where meetings are the root elements and the persons are attached to the persons.
I assumed QSqlRelationalTableModel or other model-driven widgets was the way to go, but I am open for all kind of solutions.
I have not looked into QDataWidgetMapper and will learn about it.
I find that creating views in the database simplifies my code immensely. I use Postgres and use instead of triggers for updates and inserts, so I can use a qsqltableview for a lot. I don't know if MySql can do that though, being unfamiliar with it.
The QDataWidgetMapper is useful for mapping a single record into a detail form.
i am refering to this topic again and I would like to ask @pantarhei , how did you solve view, editation of database relationship and n:m.