The reason I set my ID method to none was because I couldn't get Torque to work correctly with my preexisting tables. Our database is MS SQL Server 2000, and all our tables use an identity column for the primary key. When I had autoincrement set, I seem to recall that it would try and insert my primary key value, with a null, or something like that.. (I don't quite recal). When I switched to none, it worked. I understand though that "none" is deprecated, and at somepoint, "autoincrement" will do what I want.
I will run another test with autoincrement to verify the behavoir I was getting. BTW, I am using TDK 2.1 Eric -----Original Message----- From: Scott Eade [mailto:[EMAIL PROTECTED]] Sent: Friday, December 07, 2001 6:12 PM To: Turbine Users List Subject: Re: Copying and then saving a row into DB, how do I get the primary key From: "Pugh, Eric" <[EMAIL PROTECTED]> > I read/searched around, and it seems that when you do the insert in the save > method of the BasePeer, you should get an object back with the primary key. > However, I get a null, which I think is because my idMethod is none. > Therefore after the insert, Torque has no idea what the primary key was, > because it is an identity column. I totally missed that you said your idMethod was "none". With "none" how would you expect an id to be generated? How does the id get assigned to the original object? Assuming you are using tdk2.1 why not set idMethod to "autoincrement" and let the database allocate the ids for you. I much prefer "autoincrement" over "idbroker" as it allows you to create records external to your application. > > I ended up doing a custom executeQuery: Select max(product_id) from > products. However this does raise the issue that if two people do two > inserts at the same time, they might both get the same product id back! I assume idBroker takes steps to prevent this. "autoincrement" should handle this also. > I will try the setNew. What does that actually do (other then tell torque > that its needs to do an insert)? Also, I think doing the copy causes the > setNew(true) to happen. Yes, it tells torque to do an insert. Copy may well set the new flag. Ultimately my comment was misdirected because I skipped over your idMethod. > Eric Cheers, Scott -- To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]> For additional commands, e-mail: <mailto:[EMAIL PROTECTED]> -- To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]> For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>
