PDA

View Full Version : QSqlRelation confusion, this should be simple.



neuron
21st January 2009, 18:41
I got two tables (actually, tons, but lets focus on these), this is their setup:


CREATE TABLE Content (id INTEGER NOT NULL PRIMARY KEY, title TEXT NOT NULL, released DATE, rating INTEGER, tagline TEXT,plot TEXT, ended DATE,status TEXT);
CREATE TABLE Url (id INTEGER NOT NULL PRIMARY KEY, contentId INTEGER NOT NULL REFERENCES Content (id), url TEXT NOT NULL, scraper TEXT);


Every content can have a list of url's connected to them. And I got an editwindow that shows all the data in content quite nicely, and then I wanted to add (using sql relations) url's to a view of it's own, that's where my problems come in.

Every example I can find uses a foreign key in the main table to referance a remote table, however I dont have that, it's a foreign key in the remote table linking back.

Is there any way to use sql relations to get a model of urls from the content model? Or will I have to setup a seperate url model?

tmat256
22nd January 2009, 00:14
You probably have to set up a separate model for the url.

My experiences with the relational table models usually goes as follows:

- Set up the models
- Get the views to work properly
- Struggle to get edits of the relational data to work
- Rewrite the whole thing as a QAbstractItemModel (or equivalent)
- Get edits working
- ???
- Profit

neuron
22nd January 2009, 12:29
hmpf :/, I was really hoping for some tools to work with a table model that simple. Oh well, I'll work around it, thanks for your help :)