Re: existing tables with id autogenerated

Date: Nov 7, 2007

Once you've set up your connection to MySQL (see JP van de Giessen's post), you can map a Database Record to a table as follows:Name the database record using the table name in the database (note that mapping is case insensitive and replaces spaces and other non-alphanumeric characters with underscores, so that the Tersus database record element Stock Item will map to the database table STOCK_ITEM), or alternatively call it whatever you like in Tersus and override the name mapping by setting tableName shared property to the name in the database. Columns map in the same manner, except that overriding is achieved by adding a columnName local property to each field and setting it.

Mapping auto-generated fields is tricky (to be more precise the tricky part is inserting data to it, as opposed to find, update & delete which should work seamlessly).Try one of the following options (success is dependent on the specific database used):

Leave the auto-generated field empty (null)

Create another database record element (call it B) which is identical to the one discussed above (call it A) except that it does not include the auto-generated field. Use this database record for inserting.In fact to avoid having to maintain practically identical field lists in 2 separate database record elements in the model. you can create one (call it A) without the auto-generated Id, and then create the other (B) which includes the auto-generated field and A, but make sure that A (in B) has local property excludeFromFieldName set to true, otherwise Tersus will assume the field names are prefixed in the database with the string A_ .

Note that both options are problematic, in that Insert will not return the auto-generated Id. You may be able to overcome by writing a stored procedure which inserts the data and returns the Id.

See Also:

To use the full functionality of this web site, JavaScript needs to be turned on.