David Zhao wrote:
> Hi there,
> 
> How do I either check if a certain record exists in the table using Torque
> OM class, or insert a new record, and retrieve the last_inserted_id?
> Thanks,

1.) There are two ways. Either you set up a Criteria object containing
the primary key (see the XXXPeer.buildCriteria(pk) method), run a
XXXPeer.doSelect(criteria) and check if the returned list is empty. Or
you use XXXPeer.retrieveByPK(pk) and catch the NoRowsException.

2.) If an object isNew(), it will be inserted into the database on
save(). Then the primary key fields are updated with the value of the id
just created. So you can check for this value using getPrimaryKey()
after save. If you do  this in a transaction, you can use this value
immediately to set it in dependent objects.

Bye, Thomas.


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to