Railsでテーブルを作るときの注意

ActiveRecordで予約されたメソッド名をテーブルのフィールド名として使うとエラーになるので注意しましょう。
「SELECT * FROM」を使わないで、「SELECT attributes as attr FROM」というように別名を定義して使えばいいらしいですが、最初から予約メソッド名は使わないほうが吉なので「使ってはいけないカラム(フィールド)名一覧」を自分用メモとして貼っておきます。

ActiveRecordで使ってはいけないカラム(フィールド)名一覧

  == === =~
[] []=
__id__ __send__ `
acts_like? after_create after_destroy
after_save after_update after_validation
after_validation_on_create after_validation_on_update allow_concurrency
attribute_for_inspect attribute_names attribute_present?
attribute_types_
cached_by_default
attributes attributes=
attributes_before_type_cast
b64encode becomes before_create
before_destroy before_save before_update
before_validation before_validation_on_create before_validation_on_update
binding_n blank? breakpoint
class clear clear_aggregation_cache
clear_association_cache clone colorize_logging
column_for_attribute conditions configurations
connection copy_instance_variables_from
daemonize dclone debugger
decode64 decode_b decrement
decrement! default_timezone destroy
destroy_with_callbacks destroy_with_transactions destroy_without_callbacks
destroy_without_
transactions
display dup
duplicable?
enable_warnings encode64 enum_for
eql? equal? errors
extend extend_with_
included_modules_from
extended_by
freeze from_json from_xml
frozen?
gem
has_attribute? hash
id id= id_before_type_cast
increment increment! inspect
instance_eval instance_exec instance_of?
instance_values instance_variable_defined? instance_variable_get
instance_variable_set instance_variables is_a?
kind_of?
load lock! lock_optimistically
locking_enabled? logger
method method_missing methods
new_record? nil?
object_id
pluralize_table_names pretty_inspect pretty_print
pretty_print_cycle pretty_print_inspect pretty_print_
instance_variables
primary_key_prefix_type private_methods protected_methods
proxy_owner proxy_reflection proxy_target
public_methods
query_attribute quoted_id
read_attribute read_attribute_
before_type_cast
readonly!
readonly? record_timestamps reload
remove_subclasses_of require require_association
require_dependency require_gem require_library_or_gem
require_or_load reset respond_to?
respond_to_
without_attributes?
returning rollback_active_
record_state!
save save! save_with_transactions
save_with_transactions! save_with_validation save_with_validation!
save_without_transactions save_without_transactions! save_without_validation
save_without_validation! schema_format send
send! silence_stderr silence_stream
silence_warnings singleton_methods start
subclasses_of suppress
table_name_prefix table_name_suffix taguri
taguri= taint tainted?
target to_a to_enum
to_json to_param to_query
to_s to_xml to_yaml
to_yaml_properties to_yaml_style toggle
toggle! transaction type
unloadable unserializable_attribute? unserialize_attribute
untaint update_attribute update_attribute_with_
validation_skipping
update_attribute_without_
validation_skipping
update_attributes update_attributes!
valid? valid_with_callbacks? valid_without_callbacks?
validate validate_on_create validate_on_update
verification_timeout
with_options write_attribute

※ このテーブルは「ActiveRecord::Base.instance_methods.sort」で取得したもの(191件)に、こちら(→http://wota.jp/ac/?date=20070925)に書かれてあった何件かを足してあります。

参考

  1. こちら(→http://wota.jp/ac/?date=20070925)が元ネタ(オリジナル)です。いつも参考にさせていただいてます。
  2. こちら(→ruby on rails: うる聖やつら)で予約名とぶつかったときの回避法を知りました。