Skip to content
cgthornt edited this page Dec 1, 2014 · 6 revisions

Add Indexes to Migration

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

Make the Base Class "Abstract"

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
Clone this wiki locally