我的模型架构:
轮询
has_many :questions
has_many :responses :through => :questions
问题
belongs_to :poll
has_many :responses
回复
belongs_to :question
当我尝试运行时出现问题,或者@poll.responses.delete_all
我收到此错误:clear
destroy_all
ActiveRecord::HasManyThroughCantAssociateThroughHasOneOrManyReflection: Cannot modify association 'Poll#responses' because the source reflection class 'Response' is associated to 'Question' via :has_many.
更新:仍然不确定为什么会这样,但这里有一个解决方法:
@poll.responses.each(&:destroy)