Rails: validate presence of parent_id in has_many association
问题 I have a projects resource that has many tasks. I want to ensure that every task has a project_id by adding validates_presence_of :project_id to the tasks model. However, when creating a new project with tasks, the project_id won't be available until the record saves, therefore I can't use validates_presence_of :project_id . So my question is, how do I validate presence of project_id in the task model? I want to ensure every task has a parent. ... class Project < ActiveRecord::Base has_many