[Qt-interest] QSqlRelationalTableModel "left join"

Robert Hairgrove evorgriahr at hispeed.ch
Tue Feb 3 19:56:17 CET 2009


Linos wrote:
> Hello all,
>     do i have any way to create a relation without make it mandatory? i 
> have any fields on database that can be null but if they are not null 
> they have to be a valid value from other table. Thanks.
> 
> Regards,
> Miguel Angel.

What you need is a default value for the related (foreign) table which 
corresponds to an existing row in the other (master) table. For example, 
if I have a table "Occupation" which has different kinds of jobs (e.g. 
baker, truck driver, banker, ...) and it had a primary key column of 
integer type, there could be one row with PK = 0 and text "(unknown)". 
In the related table, the correlated column's default value would be 0 
and never NULL.

If the PK for the master table is automatically generated, e.g. 
autoincrement starting with 1, you can still insert the row with 0 
manually (i.e., SQL "INSERT INTO...").



More information about the Qt-interest-old mailing list