Note

3年後の自分のために書いています

ActiveRecord で create_xx, build_xx 系のメソッドが作られるのは has_one した時だけ

表題の通りですが、 has_many した時も create_xxs 的なメソッドが自動生成されると勘違いしていたのでメモ。

ActiveRecord::Associations::ClassMethods

class Project < ActiveRecord::Base
  has_one :project_manager
  has_many :milestones
end

Project#create_project_manager(attributes={}) はいけるけど、 Project#create_milestones(attributes={}) はいけないという話。

やっぱり Rails ガイドよりも Ruby on Rails API の方が正確かつ詳細な情報があって良いですな。