創建新記錄時。我需要爲同一模型創建更多記錄。在before_save上創建新記錄
例::
class XYZ < ActiveRecord
def before_save
# At this point object is already initialized ..
# And it's containing values.
# At this point i want to create 10 more records for the same class.
# something like this
XYZ.new(:att1 => value1,:att2 => value2,:att3 => self.att1)
end
end
請問有什麼可以處理這種情況的? 在哪個回調中,我必須爲同一個模型創建更多記錄?
你是否也希望爲那些*觸發before_save? – 2010-10-14 19:10:47
@馬克托馬斯是驗證和回調需要對那些火。 – 2010-10-14 19:15:02
你打算如何阻止before_saves創建的無限循環被before_saves創建的額外記錄調用? – 2010-10-14 19:19:10