Primary Keys that aren't incremental

0 views
Skip to first unread message

Stephen Moretti

unread,
May 9, 2008, 12:45:24 PM5/9/08
to transf...@googlegroups.com
I suspect I'm being really dim (as usual)

I have a primary key which is a supplied value from a data import - basically a clients internal stock id for a "product".

How do I persuade Transfer to let me set my own key?

I've tried :
<id name="ID" column="StockID" type="numeric"  />
and
<id name="ID" column="StockID" type="numeric" generate="true" />

The first throws a  SQL error because the insert is not including the ID in the INSERT statement, as the database requires a value and there is no default set for it.
The second inserts an incremental ID that Transfer is kindly generating and not inserting the ID that I set using objProduct.setID(blah)

I'm using Winders, CF8, MySQL 5.x and the latest Transfer from SVN.
I did try reading the docs and searching, but don't seem to be able to hit on what I'm after.  The stupid thing is I'm sure I've done this before, but can't find it, nor can I remember what I did!

Thanks for the help

Regards

Stephen

Casey Corcoran

unread,
May 9, 2008, 12:49:45 PM5/9/08
to transf...@googlegroups.com

This is from the docs, sounds like what you're looking for...


http://docs.transfer-orm.com/wiki/Primary_Key_Management.cfm


Manual

Lastly, this can all be manually overwritten simply by setting the
primary key value via the set() method prior to the TransferObject being
created in the database, e.g.

||

user = getTransfer().new("User");
user.setUserID(1);
getTransfer().save(user);

This will attempt to insert the User record into the database with a ID
of '1'.

Stephen Moretti

unread,
May 10, 2008, 3:24:37 PM5/10/08
to transf...@googlegroups.com


2008/5/9 Casey Corcoran <casey.c...@gmail.com>:



     This is from the docs, sounds like what you're looking for...


     http://docs.transfer-orm.com/wiki/Primary_Key_Management.cfm


     Manual

Lastly, this can all be manually overwritten simply by setting the
primary key value via the set() method prior to the TransferObject being
created in the database, e.g.

||

user = getTransfer().new("User");
user.setUserID(1);
getTransfer().save(user);

This will attempt to insert the User record into the database with a ID
of '1'.

Yeah - thanks Casey.  This is why I'm confused and thinking I'm being dim... I've read this already.

In both of the examples I give I am doing a setID() and, as I said, in the first example the ID column is not in the query and in the second Transfer is ignoring the setID() and generating an incrementing ID for me. :/

I'll have a bit more of a dig on monday...  I'll see if the ID is actually being set in the object, despite the line of code being right there, before I do the save and if it is I'll dig deeper into Transfer to see what why it might be being skipped over.

Regards

Stephen
Reply all
Reply to author
Forward
0 new messages