Henry, that actually looks like it should solve my issue, I'll let you know when I've had a chance to implement and test !!
On May 10, 8:44 pm, Henry Baragar <[email protected]> wrote: > Perchance you want some like the following (completely untested)... > > In your user model: > > fields do > ... > rsvp_id :integer, :default => 0 > end > > def take_next_rsvp_id! > self.rsvp_id += 1 > save > rsvp_id > end > > In your RSVP model: > > def before_create > self.user_private_id = user.take_next_rsvp_id! > end > > Hope this helps. > > Henry > > On 10-05-10 06:54 PM, Jeremy Savoy wrote: > > > > > > > Not saying no gaps, in fact if an Invitation is deleted the gap in > > numbers must remain, because once you physically write an RSVP ID on > > an invitation and send it out in the mail, then that RSVP ID must not > > be changed by the software. > > > This is why acts_as_list wont' work, because when you remove one all > > records beyond that would get renumbered (reordered really). > > > The RSVP ID is used to quickly locate the record in the system by the > > user when the RSVP is returned in the mail. This is a hard > > requirement. > > > So each invitation/rsvp needs it's own unique id, but invitation_id > > won't work because that is unique for the entire table. Each user > > needs to have their set of RSVP ID's start at 1 (Invitations and RSVPs > > are tracked by the same model and the terms are used interchangeably > > here) > > > --jeremy > > > On May 10, 4:23 pm, kevinpfromnm<[email protected]> wrote: > > >> There are ways to do this, but all the methods are going to be pretty > >> brittle. Why wouldn't a scoped acts_as_list work again? And why need > >> a specific no gaps numbered list anyway? > > >> On May 10, 1:44 pm, Jeremy Savoy<[email protected]> wrote: > > >>> Unfortunately they can be removed. > > >>> Perhaps I can get the highest numerical rsvp_id for my user on index > >>> action (not sure how to do this, is there a "max" function?), and then > >>> use mixins and write a before_create to +1 that value -- what are your > >>> thoughts ? > > >>> --jeremy > > >>> On May 10, 12:00 pm, Matt Jones<[email protected]> wrote: > > >>>> On Mon, May 10, 2010 at 10:31 AM, Jeremy Savoy<[email protected]> > >>>> wrote: > > >>>>> I have a need to have an auto_increment field in a table that is > >>>>> unique on a a per-user basis. The scenario is that I have Invitations/ > >>>>> RSVPs that are physically tracked via a number (RSVP ID) for quick > >>>>> reference. > > >>>>> This number needs to be auto_incremeted based on the owner of the > >>>>> record, so that each user will have their own set of RSVP ID's, > >>>>> starting with "1" and going up. > > >>>>> Is there a way to model this to have MySQL take care of this for me, > >>>>> or must I implement the arithmetic for the mangement of this value on > >>>>> the ruby side? > > >>>> There's not (AFAIK) any way to make MySQL do this directly. > > >>>> If RSVPs aren't ever deleted, you could try faking this using > >>>> acts_as_list, scoped to an appropriate field on the RSVP record. That > >>>> would give you the sequence, but deleting a record in the middle will > >>>> cause mayhem... > > >>>> --Matt Jones > > >>>> -- > >>>> You received this message because you are subscribed to the Google > >>>> Groups "Hobo Users" group. > >>>> To post to this group, send email to [email protected]. > >>>> To unsubscribe from this group, send email to > >>>> [email protected]. > >>>> For more options, visit this group > >>>> athttp://groups.google.com/group/hobousers?hl=en. > > >>> -- > >>> You received this message because you are subscribed to the Google Groups > >>> "Hobo Users" group. > >>> To post to this group, send email to [email protected]. > >>> To unsubscribe from this group, send email to > >>> [email protected]. > >>> For more options, visit this group > >>> athttp://groups.google.com/group/hobousers?hl=en. > > >> -- > >> You received this message because you are subscribed to the Google Groups > >> "Hobo Users" group. > >> To post to this group, send email to [email protected]. > >> To unsubscribe from this group, send email to > >> [email protected]. > >> For more options, visit this group > >> athttp://groups.google.com/group/hobousers?hl=en. > > -- > You received this message because you are subscribed to the Google Groups > "Hobo Users" group. > To post to this group, send email to [email protected]. > To unsubscribe from this group, send email to > [email protected]. > For more options, visit this group > athttp://groups.google.com/group/hobousers?hl=en. -- You received this message because you are subscribed to the Google Groups "Hobo Users" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/hobousers?hl=en.
