Can I use UUID''s for primary keys with rails? WIll this break anything? Is rails ''smart'' enough to deal with UUID''s? _______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
The simple answer is ''no'', Rails cannot do that. Although if someone is working on an extension to ActiveRecord to support UUID pks I would certainly be able to make use of it at my client. On 10/7/05, robi sen <robisen-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Can I use UUID''s for primary keys with rails? WIll this break anything? Is > rails ''smart'' enough to deal with UUID''s? > > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails > > >
You can use GUIDs (or UUIDs if you prefer). This can easily be done using the ruby module http://rubyforge.org/projects/uuid/ . What you need to do is be sure to set your ID for all newly created objects to a new GUID. Then with a little hackery and awareness that you have deviated from the norm you can get all your objects to place nice. For example, from one of my controllers: def create @customer = Customer.new(@params[:customer]) @customer.id = Guid.new.to_s if @customer.save flash[''notice''] = ''Customer was successfully created.'' redirect_to :action => ''list'' else render_action ''new'' end end Hopefully that makes sense. Regards, Lee On 10/7/05, Obie Fernandez <obiefernandez-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> The simple answer is ''no'', Rails cannot do that. Although if someone > is working on an extension to ActiveRecord to support UUID pks I would > certainly be able to make use of it at my client. > > On 10/7/05, robi sen <robisen-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > Can I use UUID''s for primary keys with rails? WIll this break anything? Is > > rails ''smart'' enough to deal with UUID''s? > > > > _______________________________________________ > > Rails mailing list > > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > > http://lists.rubyonrails.org/mailman/listinfo/rails > > > > > > > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >
thanks lee On 10/8/05, Lee Gonzales <lee.gonzales-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > You can use GUIDs (or UUIDs if you prefer). This can easily be done > using the ruby module http://rubyforge.org/projects/uuid/ . What you > need to do is be sure to set your ID for all newly created objects to > a new GUID. Then with a little hackery and awareness that you have > deviated from the norm you can get all your objects to place nice. > > For example, from one of my controllers: > > def create > @customer = Customer.new(@params[:customer]) > @customer.id <http://customer.id> = Guid.new.to_s > > if @customer.save > flash[''notice''] = ''Customer was successfully created.'' > redirect_to :action => ''list'' > else > render_action ''new'' > end > end > > > Hopefully that makes sense. > > Regards, > Lee > > > On 10/7/05, Obie Fernandez <obiefernandez-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > The simple answer is ''no'', Rails cannot do that. Although if someone > > is working on an extension to ActiveRecord to support UUID pks I would > > certainly be able to make use of it at my client. > > > > On 10/7/05, robi sen <robisen-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > Can I use UUID''s for primary keys with rails? WIll this break > anything? Is > > > rails ''smart'' enough to deal with UUID''s? > > > > > > _______________________________________________ > > > Rails mailing list > > > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > > > http://lists.rubyonrails.org/mailman/listinfo/rails > > > > > > > > > > > _______________________________________________ > > Rails mailing list > > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > > http://lists.rubyonrails.org/mailman/listinfo/rails > > > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >_______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails