看板 Ruby 關於我們 聯絡資訊
環境: Ruby 1.9.2 Rails 3 狀況: 我在閱讀Rails Guide時,發現 after_initialize 和 after_find 沒有相對的 before_initialize 及 before_find 並說要使用時必須以 method define,不能用 handler 摘錄: If you try to register after_initialize or after_find using macro-style class methods, they will just be ignored. This behaviour is due to performance reasons, since after_initialize and after_find will both be called for each record found in the database, significantly slowing down the queries. 我覺得這樣的解釋我還是看不太懂 1. 這和 self reflection 有關係嗎? 2. 一個 select query 可能包涵數萬筆資料,不管是用 method define 還是 handler ,都要被呼叫數萬次吧?如此效能還不是一樣差嗎? 3. 對一個 callback 同時使用 method define 和 handler 會導致 handler 被蓋掉嗎? 4. 我想看原始碼,但是在github裡面有如大海撈針,希望得到眾神的指引 附錄: http://goo.gl/17Zmh 章節10.4 ---
ayamomiji:我想是因為這兩個事件發生時, 還沒有對應的 instance 08/25 13:26
願聞其詳QQ ※ 編輯: tonytonyjan 來自: 61.227.147.76 (08/25 19:09)