I take naming pretty seriously, so I think pretty hard about good names for my ActiveRecord models. However, I frequently come up with a name and it has some conflict with a reserved name, either in the database or Ruby or Rails. Model or field names like set
or group
. Sometimes the issue isn't immediately apparent either. Is there a list somewhere of names we can't use in our model names and a list for field names?
Active Record uses naming conventions for the columns in database tables, depending on the purpose of these columns. Foreign keys - These fields should be named following the pattern singularized_table_name_id (e.g., item_id , order_id ).
ActiveRecord::Base indicates that the ActiveRecord class or module has a static inner class called Base that you're extending.
What is ActiveRecord? ActiveRecord is an ORM. It's a layer of Ruby code that runs between your database and your logic code. When you need to make changes to the database, you'll write Ruby code, and then run "migrations" which makes the actual changes to the database.
One of the primary aspects of ActiveRecord is that there is very little to no configuration needed. It follow convention over configuration. ActiveRecord is commonly used with the Ruby-on-Rails framework but you can use it with Sinatra or without any web framework if desired.
Reserved Word List
ADDITIONAL_LOAD_PATHS ARGF ARGV ActionController ActionView ActiveRecord ArgumentError Array BasicSocket Benchmark Bignum Binding CGI CGIMethods CROSS_COMPILING Class ClassInheritableAttributes Comparable ConditionVariable Config Continuation DRb DRbIdConv DRbObject DRbUndumped Data Date DateTime Delegater Delegator Digest Dir ENV EOFError ERB Enumerable Errno Exception FALSE FalseClass Fcntl File FileList FileTask FileTest FileUtils Fixnum Float FloatDomainError GC Gem GetoptLong Hash IO IOError IPSocket IPsocket IndexError Inflector Integer Interrupt Kernel LN_SUPPORTED LoadError LocalJumpError Logger Marshal MatchData MatchingData Math Method Module Mutex Mysql MysqlError MysqlField MysqlRes NIL NameError NilClass NoMemoryError NoMethodError NoWrite NotImplementedError Numeric OPT_TABLE Object ObjectSpace Observable Observer PGError PGconn PGlarge PGresult PLATFORM PStore ParseDate Precision Proc Process Queue RAKEVERSION RELEASE_DATE RUBY RUBY_PLATFORM RUBY_RELEASE_DATE RUBY_VERSION Rack Rake RakeApp RakeFileUtils Range RangeError Rational Regexp RegexpError Request RuntimeError STDERR STDIN STDOUT ScanError ScriptError SecurityError Signal SignalException SimpleDelegater SimpleDelegator Singleton SizedQueue Socket SocketError StandardError String StringScanner Struct Symbol SyntaxError SystemCallError SystemExit SystemStackError TCPServer TCPSocket TCPserver TCPsocket TOPLEVEL_BINDING TRUE Task Text Thread ThreadError ThreadGroup Time Transaction TrueClass TypeError UDPSocket UDPsocket UNIXServer UNIXSocket UNIXserver UNIXsocket UnboundMethod Url VERSION Verbose YAML ZeroDivisionError @base_path accept Acces Axi action attributes application2 callback category connection database dispatcher display1 drive errors format host key layout load link new notify open public quote render request records responses save scope send session system template test timeout to_s type URI visits Observer
Database Field Names
created_at created_on updated_at updated_on deleted_at (paranoia gem) lock_version type id #{table_name}_count position parent_id lft rgt quote_value
Ruby Reserved Words
alias and BEGIN begin break case class def defined? do else elsif END end ensure false for if module next nil not or redo rescue retry return self super then true undef unless until when while yield _ FILE _ _ LINE _
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With