On page 198 Patrick generates a Vote model by:

ruby script/generate model Vote story_id:integer

and then changes the vote/story class so that they read:

class Vote < ActiveRecord::Base
belongs_to :story
end

class Story < ActiveRecord::Base
has_many :votes
end

Would an equivalent database schema be derived by not adding the story_id:integer as so:


ruby script/generate model Vote

and then change the vote/story class so that they read:

class Vote < ActiveRecord::Base
belongs_to :story
end

class Story < ActiveRecord::Base
has_many :votes
end

and changing the create_stories.rb migration to read thus:

class CreateStories < ActiveRecord::Migration
def self.up
create_table :stories do |t|
t.string :name
t.string :link

t.timestamps
end
add_column :votes, :story_id, :integer
end

def self.down
drop_table :stories
remove_column :votes, :story_id
end
end

##################################################

It seems to me that this gets the story_id column in the votes table, but allows for it to be removed again through a migration. The hard coded addition to the model seems to preclude the schema from ever being changed.

Is there a distinction, or was this done for pedagogical reasons?

Thanks,

John