0
我想在創建另一個對象後創建一個對象,但後一個對象是使用SQL查詢而不是ActiveRecord查詢創建的。after_create in Rails with manual SQL query
我想創建一個EVENTCODE時XYZ的新實例如下創建:
class xyz < abc
after_create :create_event_code
def create_event_code
event = UtilityDrEvent.find(self.utility_dr_event_id)
participant = ParticipantAccount.find(self.participant_account_id)
EventCode.generate_and_save(event, participant)
end
end
但XYZ的新實例由此產生:
insert_sql = 'INSERT INTO xyz (a_id, b_id)'
所以after_create方法從未打過電話我怎樣才能使這個工作?