开发者

ActiveRecord partial updates in Padrino

How do I configure ActiveRecord to use partial_updates in a Padrino application?

Customer < ActiveRecord::Base
  after_update :check_name_change

  private
  def check_name_change
    开发者_如何学JAVAif name_changed?
      # send mail notification for change of name.
    end
  end
end

Consider the User has attributes 'name' and 'country' among others in the database.

When user updates name, it sends an email notification as expected. However, even when the user changes the country (or any other) attribute, it sends the notification for name change which is unacceptable.

Upon checking the logs, I found that the update query for country is making a full update, setting all the attributes of the user record. As such the name_changed? method returns true and notification email for name change is sent.

If I put the following line in app.rb

ActiveRecord::Base.partial_updates = true

I see no difference. Any update_attribute calls still do a full update of the record.

Is there any other solution or workaround?


This is not related to padrino but only to active record.

Try it on before_save.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜