Hi, There''s an entry on the wiki about not using enum columns in mysql: http://wiki.rubyonrails.com/rails/show/HowtoUseSetAndEnumColumns I don''t know how old it is though (since the wiki import) so I can''t tell whether the page is out-of-date and if enum columns are now considered ''supported'' or not. They seem to work for me ''sort-of'' but they''re not 100% bulletproof which makes me wonder whether the fact that they work at all is a fluke. Can anyone shed any light? Should I continue to stick to the advice in the wiki? Thanks in advance, Trevor
>From what i know they are NOT supported. this is due to trying tokeep ActiveRecord as generic as possible, and ENUM is not a SQL Standard datatype. im pretty sure you can use validations with the text AR gives you to ensure they work as the wiki says. i also noticed an Enum type either in core ruby or the stdlib. you could probably easily wrap the column in accessors to use that type, or even create your own acts_as_enum :field module for future use. -- just an idea On 8/12/05, Trevor Squires <trevor-k8q5a0yEZAgS+FvcfC7Uqw@public.gmane.org> wrote:> Hi, > > There''s an entry on the wiki about not using enum columns in mysql: > > http://wiki.rubyonrails.com/rails/show/HowtoUseSetAndEnumColumns > > I don''t know how old it is though (since the wiki import) so I can''t > tell whether the page is out-of-date and if enum columns are now > considered ''supported'' or not. > > They seem to work for me ''sort-of'' but they''re not 100% bulletproof > which makes me wonder whether the fact that they work at all is a > fluke. > > Can anyone shed any light? Should I continue to stick to the advice in > the wiki? > > Thanks in advance, > Trevor > > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-- Zachery Hostens <zacheryph-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
Enums aren''t supported because they aren''t in the nature of dynamic typing. It goes against the grain :) Jake Zachery Hostens wrote:>>From what i know they are NOT supported. this is due to trying to >keep ActiveRecord as generic as possible, and ENUM is not a SQL >Standard datatype. im pretty sure you can use validations with the >text AR gives you to ensure they work as the wiki says. > >i also noticed an Enum type either in core ruby or the stdlib. you >could probably easily wrap the column in accessors to use that type, >or even create your own > >acts_as_enum :field > >module for future use. -- just an idea > >On 8/12/05, Trevor Squires <trevor-k8q5a0yEZAgS+FvcfC7Uqw@public.gmane.org> wrote: > > >>Hi, >> >>There''s an entry on the wiki about not using enum columns in mysql: >> >>http://wiki.rubyonrails.com/rails/show/HowtoUseSetAndEnumColumns >> >>I don''t know how old it is though (since the wiki import) so I can''t >>tell whether the page is out-of-date and if enum columns are now >>considered ''supported'' or not. >> >>They seem to work for me ''sort-of'' but they''re not 100% bulletproof >>which makes me wonder whether the fact that they work at all is a >>fluke. >> >>Can anyone shed any light? Should I continue to stick to the advice in >>the wiki? >> >>Thanks in advance, >>Trevor >> >>_______________________________________________ >>Rails mailing list >>Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org >>http://lists.rubyonrails.org/mailman/listinfo/rails >> >> >> > > > >
Jake Good <jake-UDG8+2NMCBIv34k0vaUUyg@public.gmane.org> writes:> Enums aren''t supported because they aren''t in the nature of dynamic typing. > > It goes against the grain :)Dynamic typing doesn''t eliminate the need for enums. I''m a huge fan of dynamic typing and I''ve used it for years. I still use enums, but usually have to roll my own. The acts_as_enum :field is a good idea. I''ve kinda got some of that done in my app; just not that simplified. -- doug-jGAhs73c5XxeoWH0uzbU5w@public.gmane.org
> I don''t know how old it is though (since the wiki import) so I can''t > tell whether the page is out-of-date and if enum columns are now > considered ''supported'' or not.So long as you only insert valid values they should work, but no, they''re not supported.> They seem to work for me ''sort-of'' but they''re not 100% bulletproof > which makes me wonder whether the fact that they work at all is a > fluke.Somehting like that.> Can anyone shed any light? Should I continue to stick to the advice in > the wiki?Either stick to the advice there, or introduce models which represent those values. i.e if an account can either be opened, closed, delinquent, suspended or new. Instead of having an enum column have: class AccountStatus < ActiveRecord::Base end class Account < ActiveRecord::Base belongs_to :account_status end> Thanks in advance, > Trevor > > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-- Cheers Koz
On Aug 12, 2005, at 11:40 AM, Trevor Squires wrote:> They seem to work for me ''sort-of'' but they''re not 100% bulletproof > which makes me wonder whether the fact that they work at all is a > fluke. > > Can anyone shed any light? Should I continue to stick to the > advice in the wiki? >When I first began my project we were using ENUM in MySql. A decision was made that we would have to use Sybase instead as it was the corporate standard. I ported the ENUM behavior to a check constraint in Sybase. The nice thing I got from using an ENUM or check constraint is a helper that generates a drop-down based on the possible values in the enum. This makes it very easy to create forms with selections driven by the database constraints. The code is pretty specific to what we are doing, but I will try to generalize it and submit it. I think the portability issue is not as much of an issue as is stated in the wiki statement. Most databases support some form of column check validation. Will Sobel _______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails