-
Notifications
You must be signed in to change notification settings - Fork 86
Useful Tips
cgthornt edited this page Dec 1, 2014
·
6 revisions
Adding an index causes lookups to perform much faster as the table size grows:
create_table :products do |t|
t.actable index: true
t.string :name
end
You might want to ensure your base class has a child:
product = Product.create! name: 'No Child'
product.specific # => nil
You should add both a database-level constraint:
create_table :products do |t|
t.actable null: false
t.string :name
end
Now if you try to save, you now get an error:
Product.create! name: 'No Child' # => ERROR: null value in column "actable_id" violates not-null constraint