You are viewing a plain text version of this content. The canonical link for it is here.
Posted to torque-user@db.apache.org by David Zhao <wz...@gmail.com> on 2006/10/18 23:51:33 UTC

find or create method using Torque

Hi there,

Is there a way using peer class in Torque to either retrieve an
existing record's ID or create a new record and return the new ID in
one call, something like find_or_create?

Thanks in advance!

David

---------------------------------------------------------------------
To unsubscribe, e-mail: torque-user-unsubscribe@db.apache.org
For additional commands, e-mail: torque-user-help@db.apache.org


Re: How to check if row exists or retrieve last inserted id after insert when using Torque OM?

Posted by Thomas Vandahl <tv...@apache.org>.
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: torque-user-unsubscribe@db.apache.org
For additional commands, e-mail: torque-user-help@db.apache.org


How to check if row exists or retrieve last inserted id after insert when using Torque OM?

Posted by David Zhao <wz...@gmail.com>.
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,

David


---------------------------------------------------------------------
To unsubscribe, e-mail: torque-user-unsubscribe@db.apache.org
For additional commands, e-mail: torque-user-help@db.apache.org


RE: find or create method using Torque

Posted by Thomas Fischer <fi...@seitenbau.net>.
Hi,

I would be surprised if something like this exists.

   Cheers,

        Thomas

"David Zhao" <wz...@gmail.com> schrieb am 18.10.2006 23:51:33:

> Hi there,
>
> Is there a way using peer class in Torque to either retrieve an
> existing record's ID or create a new record and return the new ID in
> one call, something like find_or_create?
>
> Thanks in advance!
>
> David
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: torque-user-unsubscribe@db.apache.org
> For additional commands, e-mail: torque-user-help@db.apache.org
>


---------------------------------------------------------------------
To unsubscribe, e-mail: torque-user-unsubscribe@db.apache.org
For additional commands, e-mail: torque-user-help@db.apache.org