문제

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
    if 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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top