Hi, I have one field that needs to be incremented automatically, but be scoped to another column. So it should increment based on the last value of the previous row with the same value of the scoped column. I''m not trying to replace ID with another primary key or anything crazy like that, just trying to auto-increment a database column! Any idea of how to do this? Rails 3. Thanks! -- Posted via http://www.ruby-forum.com/. -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Marnen Laibow-Koser
2010-Aug-09 14:05 UTC
Re: Auto-increment column scoped to another column
Joao Silva wrote:> Hi, > > I have one field that needs to be incremented automatically, but be > scoped to another column. So it should increment based on the last value > of the previous row with the same value of the scoped column.Remember to figure out how it will behave with deleted records.> > I''m not trying to replace ID with another primary key or anything crazy > like that, just trying to auto-increment a database column! > > Any idea of how to do this? Rails 3. Thanks!acts_as_list might actually be useful here -- it does more or less this same thing with the position column. Some databases can do this on the DB side. Best, -- Marnen Laibow-Koser http://www.marnen.org marnen-sbuyVjPbboAdnm+yROfE0A@public.gmane.org -- Posted via http://www.ruby-forum.com/. -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Andre Fonseca
2010-Aug-11 20:27 UTC
Re: Re: Auto-increment column scoped to another column
I try to use the methods before or after. I think it is better to be done in the DB. -- Andre Fonseca http://www.andrefonseca.net -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Possibly Parallel Threads
- acts_as_list / acts_as_tree / acts_as_nested_set - which one
- Shoulda issue: no more "should have_instance_methods" ?
- acts_as_list query
- Difference between rake test:units and individually running ruby -I test test/unit/something_test.rb ?
- Can't install mongrel with ruby 1.9.2p136