Getting Access to a Row just Created

I’ve got a Ruby file where I take a table from my database named “Poc”
and I’ve created a row in that table by executing:

 Poc.create()

How do I access the id of the row I’ve just created? I could do some-
thing like this:

 Poc.create( :user_name => '')

and then do a “Poc.find()” that searches for a row with the empty
string as its “user_name”, but seems like such a round-about way of
doing it. Is there a more direct way?

                            ---Kevin Simonson

“You’ll never get to heaven, or even to LA,
if you don’t believe there’s a way.”
from Why Not

On Dec 8, 2007, at 1:40 PM, [email protected] wrote:

I’ve got a Ruby file where I take a table from my database named “Poc”
and I’ve created a row in that table by executing:

Poc.create()

new_one = Poc.create()

Then do what you want with new_one.id or any other field. However…

                           ---Kevin Simonson

“You’ll never get to heaven, or even to LA,
if you don’t believe there’s a way.”
from Why Not

…you ususally either do Poc.new or Poc.create with a hash of
attributes.

Then, if you started with Poc.new, you .save the record when you’re
ready.
Poc.create automatically saves, but if you change the record after you
create it, you’d have to .save that record, too.

-Rob

Rob B. http://agileconsultingllc.com
[email protected]