db-torque-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jim Menard <j...@io.com>
Subject Nullable foreign keys
Date Thu, 18 Dec 2003 14:48:30 GMT
I'm trying to understand how nullable foreign keys work in Torque.

I have a database table ("member") with a foreign key ("language_id") 
to another table. The foreign key may be null. When I load a member, 
it's language is null. Actually, the language_id seems to be set to 0, 
which really confuses me.

When I try to save the member with no changes, I see the exception

ERROR:  member_fk_2 referential integrity violation - key referenced 
from member not found in language

Of course not! There is no language record with id 0.

It looks like NULL foreign keys are stored in Torque as 0, not as NULL. 
This seems evil to me. When the member tries to save itself, it tries 
to save 0 into the language_id field, which is not a legal foreign key 
value. Why does it try to save 0 instead of saving NULL?

(I can't figure out how to search the mailing list archives. I clicked 
on the "archive" link in the Torque documentation, but that URL doesn't 
seem to be good.)

Thank you for your help.

Jim
-- 
Jim Menard, jimm@io.com, http://www.io.com/~jimm/
"Master, does Emacs have the Buddha nature?" the novice asked.
"I don't see why not. It's got bloody well everything else."
     -- John Fouhy


---------------------------------------------------------------------
To unsubscribe, e-mail: torque-user-unsubscribe@db.apache.org
For additional commands, e-mail: torque-user-help@db.apache.org


Mime
View raw message