<$BlogRSDURL$>

Thursday, May 26, 2005

Torque - idMethod 

A lot of people overlook this important attribute "idMethod" in the "table" tag of the torque schema file. This determines whether you are using the native database generated sequential key.

For instance, in MySQL,
(1) if you want your primary key to be auto-incremented by the DB, you should set the idMethod to be "native";
(2) If you want to define your own primary key, you should set it to "none";
(3) If the primary key mades up of 2 or more primary keys from other tables, you should also set it to "none".

If wrongly set, you will get "funny" errors :
in case (3), if you set the "idMethod" to "native", you will get "Duplicate Key or Foreign Key Constraint Error" when you try to insert to the table.

If for most of your table, the primary key is to be auto-incremented, you can put the defaultIdMethod="native" in the "database" tag. In this case, you only need to put idMethod="none" in the respective tables.

This page is powered by Blogger. Isn't yours?