Image of Lucian Ghinda writing for notes.ghinda.com
June 26th, 2024

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:

belongs_to association
belongs_to association

The solution I found was to use an option called to_table defined on the foreign_key attribute of TableDefinition#references

How to use `to_table`
How to use `to_table`

Documentation about this can be found at:Â