SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Zealot
    Join Date
    Jul 2004
    Location
    NC
    Posts
    194
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    ArgumentError: interning empty string and enum-column plugin

    Hello,

    I am a developer who has just started working on a large scale website in a team of 5 other developers. One of the developers has introduced some enum columns into the the database. Now, by default, active record doesn't support enum column types but I have added the enum-column plugin into our project. This has worked very well except for a few instances where he introduced enums that featured and empty string IE. enum('','Artist','Venue','Fan','Label').

    This causes the mysql_adapter.rb section of the plugin to throw a "ArgumentError: interning empty string" error in this section of code:

    Code:
    class MysqlColumnWithEnum < MysqlColumn
          include ActiveRecordEnumerations::Column
          
          def initialize(name, default, sql_type = nil, null = true)
            if sql_type =~ /^enum/i
              
              values = sql_type.sub(/^enum\('([^)]+)'\)/i, '\1').split("','").map { |v| v.intern}
              
              default = default.intern if default and !default.empty?
            end
            super(name, default, sql_type, null, values)
          end
        end
      end
    Does anyone know how I can work around this error?

    Thanks for your time!

    Clem C

  2. #2
    SitePoint Guru
    Join Date
    Aug 2005
    Posts
    986
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The problem is that v is empty, so v.intern doesn't work. Maybe you can use nil if v is empty, like this:

    Code:
    values = sql_type.sub(/^enum\('([^)]+)'\)/i, '\1').split("','").map{|v| v.intern unless v.empty?}


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •