Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Prevent creation of database columns with a reserved name #2629

Closed
marceldegraaf opened this Issue · 10 comments

5 participants

@marceldegraaf

Today I ran into this issue: apparently a database column with the name hash breaks things, resulting in a non-helpful error:

TypeError (can't convert String into Integer)

Creation of columns with reserved names should be prevented. If that is impossible, a more helpful error message would be awesome.

@ognevsky

Any other words except hash?

@marceldegraaf

Not that I'm aware of, but I have no idea how to find out. All the reserved words lists I could find online seem to be hopelessly outdated.

This page has a comprehensive list, but it is from 2007:
http://www.yup.com/articles/2007/01/31/no-reservations-about-keywords-in-ruby-on-rails

There are two wiki entries that seem to deal with reserved words, but one is empty and the other only contains a dead link:
http://wiki.rubyonrails.org/rails/pages/ReservedWords (has dead link)
http://wiki.rubyonrails.org/rails/pages/MagicFieldNames (is empty)

I could find no mention of reserved column names in the Rails Guides as well.

@isaacsanders

@marceldegraaf Is this still an issue?

@carlosantoniodasilva

@marceldegraaf hey, can you provide a patch for this? That'd be awesome, and if you need any help, just let us know. Thanks!

@marceldegraaf
@isaacsanders

Oh yah! I am just helping triage things for the Rails core team. Thanks!

@carlosantoniodasilva

@marceldegraaf sounds good, I'll leave the issue open for now and will revisit in a couple weeks. Thanks.

@carlosantoniodasilva

Just more info: I just tested with Rails 3 and was able to run the generator and migrate the database, but not instantiate / create a record:

>> HashTest.create! :name => 'fuu', :hash => 'yeah!'
ActiveRecord::DangerousAttributeError: hash is defined by ActiveRecord
    from .../gems/activerecord-3.2.3/lib/active_record/attribute_methods.rb:90:in `instance_method_already_implemented?'

Hash method is reimplemented in AR

@carlosantoniodasilva

I'm closing this as stale. Please, use the Ruby on Rails Core mailing list to ask for feedback about new features or changes in Rails, or try to create a pull request so people can review the feature with real code. You can also use the Ruby on Rails Talk mailing list for general questions and doubts about the framework. Thanks.

@Fire-Dragon-DoL

I named a column "length" (quite common) and created me a lot of troubles... I had to rename it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.