Skip to content

Instantly share code, notes, and snippets.

@rramsden
Created February 1, 2011 18:03
Show Gist options
  • Save rramsden/806280 to your computer and use it in GitHub Desktop.
Save rramsden/806280 to your computer and use it in GitHub Desktop.
create_table "parents", :force => true do |t|
t.column "name", :string
t.column "type", :string
end
###
class Parent < ActiveRecord::Base
end
class Child < Parent
end
class SubChild < Child
end
####
ruby-1.8.7-p302 > Child.all.size
=> 16
DEBUG Child Load (0.6ms) SELECT * FROM `parents` WHERE ( (`parents`.`type` = 'Child' ) )
ruby-1.8.7-p302 > SubChild.all
=> [#<SubChild>]
DEBUG SubChild Columns (72.4ms) SHOW FIELDS FROM `parents`
DEBUG SubChild Load (3.9ms) SELECT * FROM `parents` WHERE ( (`parents`.`type` = 'SubChild' ) )
ruby-1.8.7-p302 > Child.all.size
=> 17
^[4DEBUG Child Load (0.9ms) SELECT * FROM `parents` WHERE ( (`parents`.`type` = 'Child' OR `parents`.`type` = 'SubChild' ) )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment