Skip to content

Commit

Permalink
Update documentation on STI change handling
Browse files Browse the repository at this point in the history
Documenting a potential source of confusion about how STI classes handle changes.
  • Loading branch information
jamesprior committed Jun 30, 2014
1 parent 1f190b7 commit 9ca98b5
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions activerecord/lib/active_record/base.rb
Expand Up @@ -233,6 +233,15 @@ module ActiveRecord #:nodoc:
# the companies table with type = "Firm". You can then fetch this row again using
# <tt>Company.where(name: '37signals').first</tt> and it will return a Firm object.
#
# Be aware that because the type column is an attribute on the record every new
# subclass will instantly be marked as dirty and the type column will be included
# in the list of changed attributes on the record. This is different from non
# STI classes:
#
# Company.new.changed? # => false
# Firm.new.changed? # => true
# Firm.new.changes # => {"type"=>["","Firm"]}
#
# If you don't have a type column defined in your table, single-table inheritance won't
# be triggered. In that case, it'll work just like normal subclasses with no special magic
# for differentiating between them or reloading the right type with find.
Expand Down

0 comments on commit 9ca98b5

Please sign in to comment.