I’m trying to create a model for a comic book which has 1 writer and 1 artist. These are both instances of a Person. However how do I show this in my migration?
class CreateComics < ActiveRecord::Migration
def self.up
create_table :comics do |t|
t.column :name, :string
t.column :writer_id, :integer, :null => false
t.column :artist_id, :integer, :null => false
end
end
...
How do I say :writer_id should map to :person_id or is this kind of renaming frowned upon?
You create the mapping in your model class using the class_name and foreign_key option.