This question already has an answer here:
- Reserved names with ActiveRecord models 4 answers
I'm new to Rails and I just wondered if there were any protected names you should avoid using in your models? For example, would the following be valid:
class CreateModel < ActiveRecord::Migration
def change
create_table :model do |t|
t.string :hash
t.integer :count
t.timestamps
end
end
end
I realise has probably isn't a great name for a property, but it's a pure example.
Edit: All the responses were good, but I've chosen my accepted answer because it contains a link to a huge list of protected attributes.
I can remember only two:
type
, because Rails treats this property as a type of parent object in polymorphic objects.order
and any other SQL commands/statements/etc., because Rails generating SQL queries is using them and usually an exception occurs.Avoid class names, if they are defined:
Avoid column names within this list:
I personally ran into an issue where I named my model
record
:Other than that:
I had an issues with an external db and a column named "hash". The offending column can be ignored in this manner: