私はror初心者向けの本の1つを読んでいますが、参考文献には次の例があります:
class Article < ActiveRecord::Base
attr_accessible :body, :excerpt, :location, :published_at, :publisher, :title
validates :title, :presence => true
validates :body, :presence => true
belongs_to :user
has_and_belongs_to_many :categories
end
class Category < ActiveRecord::Base
attr_accessible :name
has_and_belongs_to_many :articles
end
したがって、これら 2 つのモデルは、上記のコードのように、habtm によって両方の方法で接続されることを意図しています。しかし、この本には、そのような移行を提供する必要があるとも書かれています。
class CreateArticlesCategories < ActiveRecord::Migration
def up
create_table :articles_categories, :id => false do |t|
t.integer :article
t.integer :category
end
end
def down
drop_table :articles_categories
end
end
私の質問:なぜですか?モデルの article_categories ではなく、なぜこの移行を作成する必要があるのですか?