2014-01-24 67 views
0

我目前正在修復Rails插件中的一個錯誤,並且我找到了導致問題的方法。我的猜測是,它在某種程度上與其ActiveRecord類Sprint中的一個getter方法被覆蓋有關。方法名稱是burndown,還有一個名爲burndown的屬性,它存儲序列化的散列。保存時執行覆蓋的模型getter?

class Sprint < ActiveRecord::Base 

    serialize :burndown, Hash 
    ... 

    def touch! 
    ... do stuff ... 
    self.burndown = nil 
    self.save! 
    end 

    def burndown 
    ... some crazy-ass method ... 
    end 
end 

所以殺滅方法不知何故被保存時執行,但我真的不知道爲什麼,因爲沒有面向Sprint類定義的回調。覆蓋getter方法是否有可能導致這種情況?

+0

你對模型中的任何驗證? – usha

回答

0

即使您沒有任何驗證或回調,Getter方法也會在保存時調用。

"/home/user/.rvm/gems/ruby-1.9.3-p194/gems/activemodel-3.2.13/lib/active_model/dirty.rb:143:in `attribute_change'" 
"/home/user/.rvm/gems/ruby-1.9.3-p194/gems/activemodel-3.2.13/lib/active_model/dirty.rb:117:in `block in changes'" 
"/home/user/.rvm/gems/ruby-1.9.3-p194/gems/activemodel-3.2.13/lib/active_model/dirty.rb:117:in `map'" 
"/home/user/.rvm/gems/ruby-1.9.3-p194/gems/activemodel-3.2.13/lib/active_model/dirty.rb:117:in `changes'" 
"/home/user/.rvm/gems/ruby-1.9.3-p194/gems/activerecord-3.2.13/lib/active_record/attribute_methods/dirty.rb:23:in `save'" 
"/home/user/.rvm/gems/ruby-1.9.3-p194/gems/activerecord-3.2.13/lib/active_record/transactions.rb:259:in `block (2 levels) in save'" 
"/home/user/.rvm/gems/ruby-1.9.3-p194/gems/activerecord-3.2.13/lib/active_record/transactions.rb:313:in `block in with_transaction_returning_status'" 
"/home/user/.rvm/gems/ruby-1.9.3-p194/gems/activerecord-3.2.13/lib/active_record/connection_adapters/abstract/database_statements.rb:192:in `transaction'" 
"/home/user/.rvm/gems/ruby-1.9.3-p194/gems/activerecord-3.2.13/lib/active_record/transactions.rb:208:in `transaction'" 
"/home/user/.rvm/gems/ruby-1.9.3-p194/gems/activerecord-3.2.13/lib/active_record/transactions.rb:311:in `with_transaction_returning_status'" 
"/home/user/.rvm/gems/ruby-1.9.3-p194/gems/activerecord-3.2.13/lib/active_record/transactions.rb:259:in `block in save'" 
"/home/user/.rvm/gems/ruby-1.9.3-p194/gems/activerecord-3.2.13/lib/active_record/transactions.rb:270:in `rollback_active_record_state!'" 
"/home/usha/.rvm/gems/ruby-1.9.3-p194/gems/activerecord-3.2.13/lib/active_record/transactions.rb:258:in `save'" 

所以如果重寫吸氣的屬性,確保它仍然在執行其原始功能