0
我有2個型號,一個例子:是否在has_one關係中添加新對象,而不是更新關聯?
class Report ...
belongs_to :answer_sheet
end
class AnswerSheet ...
has_one :report
end
當我做:
@answersheet.report = Report.create(:data => 'bleah')
@answersheet.save
# and then create another report and assign it to the same @answersheet
# assuming at this stage @answersheet is already reloaded
@answersheet.report = Report.create(:data => 'new data')
@answersheet.save
# (irb) @answersheet.report returns the first report with the data 'bleah' and not
# the one with the new data.
難道這是正確的行爲?
如果我想更新關聯到後面的報告,我該如何去做呢?