Define reference to an Active Record that has a custom table defined
Here is a #Rails pro tip I discovered while trying to write a migration for defining a belong_to association to a model that had a custom table instead of relying on the Rails convention:
The solution I found was to use an option called to_table
defined on
the foreign_key
attribute of TableDefinition#references
Documentation about this can be found at:Â
- Rails Guides - Active Record Migrations\#foreign_keys
- Rails Guides - Association Basics\#self-joins
- Rails API - SchemaStatements\#add_reference