I am new to Rails and I come to it from the background of Django. I agreed that the models and schema of the database are separate in Rails, online Django. However, I am still accessing the migration.
My question is pretty simple - how can I add a relationship to a model using migration? For example, I have Artist
and Song
as empty models that are subclassed by ActiveRecord::Base
at the moment, without any relationship.
I need to go to this:
class Artist < ActiveRecord::Base has_many :songs end class Song < ActiveRecord::Base belongs_to :artist end
But how can I change the scheme to reflect this using rails g migrate
? I am using Rails 3.1.3.
source share