Hi Graciano,
I did check that the value existed in the related table before trying to set it. I didn't think it would matter anyway (not until attempting to commit the data to the database at least), but still, no joy.
Here's an example of what I'm doing:
model->setTable("foo");
model->setRelation(model->fieldIndex("bar_id"),
// fetch a new, empty record
// The following fails to set 123 for the bar_id column. If I comment
// out the call to setRelation() above, this works fine. Assume that
// 123 is a valid id that exists in the bar table.
row.setValue("bar_id", 123);
model->setTable("foo");
model->setRelation(model->fieldIndex("bar_id"),
QSqlRelation("bar", "id", "bazcolumn"));
// fetch a new, empty record
QSqlRecord row = model->record();
// The following fails to set 123 for the bar_id column. If I comment
// out the call to setRelation() above, this works fine. Assume that
// 123 is a valid id that exists in the bar table.
row.setValue("bar_id", 123);
To copy to clipboard, switch view to plain text mode
Bookmarks