私はいくつかのモデルを持っています
class Product < ActiveRecord::Base
has_and_belongs_to_many :categories
end
と
class Category < ActiveRecord::Base
has_and_belongs_to_many :products
end
どうして言えないの
prod = Product.new
prod.categories << Category.new
インスタンスメソッドを追加する必要があるのに、has_and_belongs_to_many
クラスメソッドを追加するのはなぜですか?Product#categories<<
これらのクラスメソッドを使用して関連付けを設定するにはどうすればよいですか?