我還是有以下錯誤:我想刪除的問題,但我得到這個:從表中刪除?
ActiveRecord::StatementInvalid (Mysql::Error: Cannot delete or update a parent row: a foreign key constraint fails (`survey_development`.`inquiries`, CONSTRAINT `inquiries_ibfk_1` FOREIGN KEY (`question_id`) REFERENCES `questions` (`id`)): DELETE FROM `questions` WHERE `id` = 217):
我控制器
def destroy
# @question.destroy
# head :ok
# @question = Question.find(params[:id])
@question.destroy
head :ok
end
模型
class Question < ActiveRecord::Base
has_one :answer, :through => :inquiry , :dependent => :destroy
belongs_to :inquiry , :dependent => :destroy
validates_presence_of :text, :message => "ERROR!"
end
我堅持這一點: (
並且這一行是正確的「has_one:answer,:through =>:inquiry,:dependent =>:destroy」? /////////我有以下查詢:belongs_to:問題 belongs_to:受訪者 has_one:answer – 2011-04-18 09:34:32