I have a Author model and Book model # field_names => [id, name] class Author < AR::Base has_many :books end # field_names => [id, name] class Book < AR::Base belong_to :author, attr_accessor :serial_number end Now for example I have inserted two books BOOK1(id:101) and BOOK2(id:102) for a author AUTHOR1(id:30) Now when I load the author with books like Author.find_by_id (30, :include => :books) I want a way to set the serial_number incrementally for each Book according to the order of their ID field (or may be any other logic). In above example BOOK1(serial_number:1) and BOOK2(serial_number:2) Some more requirements: I need it to work even when i find Book.find_by_id(102) and expecting the serial_number to set 2 Any better recommendation? Samiron paul http://samironpaul.blogspot.com http://www.code71.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.
> I have a Author model and Book model > > # field_names => [id, name] > class Author < AR::Base > has_many :books > end > > # field_names => [id, name] > class Book < AR::Base > belong_to :author, > attr_accessor :serial_number > end > > Now for example I have inserted two books BOOK1(id:101) and > BOOK2(id:102) for a author AUTHOR1(id:30) > > Now when I load the author with books like Author.find_by_id > (30, :include => :books) > > I want a way to set the serial_number incrementally for each Book > according to the order of their ID field (or may be any other logic). > In above example BOOK1(serial_number:1) and BOOK2(serial_number:2) > > Some more requirements: > I need it to work even when i find Book.find_by_id(102) and expecting > the serial_number to set 2 > > Any better recommendation?You might look into acts_as_list at http://github.com/rails/ acts_as_list. -philip -- 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.