Foreign columns

Hi you all:

I’m reading “Rolling with Rails I” by C. Hibbs and in his example,
establishes a foreign key in a table (recipes), related to the column of
another table (categories). The thing is that he establishes this
matching in the code, but in the database he does not establish the
foreign key as such. My question is, can the “foreign” aspects in a
database be omitted in the database itself, and just establish the
“belong_to” and this stuff in the ActiveRecord classes?


ARs don’t use the database relationship of foreign keys at all. It uses
your explicit use of has_many, has_one or belongs_to within the AR
definitions to determine the foreign keys.