Database Column "type" is reserved in Rails

I made a database column called “type”. It contained a string. It was bound to Object. Everything was cool.

I wanted to create my object. But I kept getting this error.

object = Object.create(food: "P&L Burger", name: "The Matty", type: "Burgers")

Invalid single-table inheritance type: 1 is not a subclass of Object

TIL that Rails has some reserved keywords for database column names. It just so happens that the column name “type” is reserved. There are also other reserved column names.

See: Active Record Basics: 2.2 Schema Conventions

The “type” column is reserved for single-table-inheritance where the Ruby Object name would be stored in the “type” column and would be accessible through object.type #=> Object

See: Single Table Inheritance

Written on May 20, 2016 by ryanmagowan