Howdy,

I'm very new with Ruby and ActiveRecord.

I've got a table in postgres that looks something like

create table test
test_id not null default nextval('test_id_seq')
test_parent int not null
test_name varchar(20) not null


For the parent record: test_parent = test_id.

What's the best way to handle that situation in ActiveRecord?

It seems like i should do something like:
SEQ = <code to select nextval('test_id_seq')>
Test.new(:test_id => SEQ, :test_parent => SEQ, :test_name => 'woohoo' );


I'm not sure how to active the <code to select nextval()> portion with
ActiveRecord.

I tried:
seq = ActiveRecord::Base.connection.execute("SELECTnextval('test_id_seq')")

And that seems to be doable, but the PG:Result class is a little weird, so
I was hoping there was a better way.


Thanks.

Dave

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/2J1hsx_mCiYJ.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

Search Discussions

  • David Kerr at Mar 27, 2012 at 3:20 am
    bump. Just want to validate that going this route is the right way to
    go.

    Thanks

    --
    You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
    To post to this group, send email to rubyonrails-talk@googlegroups.com.
    To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
    For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouprubyonrails-talk @
categoriesrubyonrails
postedMar 23, '12 at 9:46a
activeMar 27, '12 at 3:20a
posts2
users1
websiterubyonrails.org
irc#RubyOnRails

1 user in discussion

David Kerr: 2 posts

People

Translate

site design / logo © 2022 Grokbase