This project is archived and is in readonly mode.

#5418 ✓stale
Fred Wu

:model_callbacks and :validate_callbacks options (similar to :validate => false for Model.save())

Reported by Fred Wu | August 20th, 2010 @ 01:17 AM

After doing a few searches I couldn't find an existing ticket, I apologise if this has already been covered.

update_attribute has the following two commits that changed its behaviour drastically.

http://github.com/rails/rails/commit/e4943e93c2571cba8630eec2e77000...
http://github.com/rails/rails/commit/01629d180468049d17a8be6900e27a...

Instead of having update_attribute and update_attributes behave differently (in particular, the triggering of validation), why don't we just assign the methods a default but also allow the user to override 'em?

So -

update_attribute :name, "Test User", :validate => false, :callbacks => true

This way the API is flexible enough for anyone to use, and it won't break backward compatibility.

Comments and changes to this ticket

  • Fred Wu

    Fred Wu August 24th, 2010 @ 08:51 AM

    Thoughts anyone?

    Here's a patch for model_callbacks. Since validation callbacks are called from ActiveModel, it requires more effort to make it work.

  • Neeraj Singh

    Neeraj Singh August 24th, 2010 @ 11:57 AM

    • Importance changed from “” to “Low”

    @Fred are all the tests passing?

  • Fred Wu

    Fred Wu August 24th, 2010 @ 12:47 PM

    Yes, they certainly are. :)

  • Fred Wu

    Fred Wu August 24th, 2010 @ 11:26 PM

    • Tag changed from callback, callbacks, update_attribute, update_attributes, validate, validation to callback, callbacks, patch, update_attribute, update_attributes, validate, validation

    Here is an updated patch.

    Added ':model_callbacks' and ':validate_callbacks' options. model_callbacks option triggers callbacks on :save, :update, :destroy and :touch, and validate_callbacks option triggers varies validation callbacks. These options by default are set to true, so that backward compatibility is maintained.
    
  • Fred Wu

    Fred Wu August 25th, 2010 @ 02:49 AM

    • Title changed from “Behaviour of update_attribute and update_attributes (set validation and callbacks)” to “[PATCH] :model_callbacks and :validate_callbacks options (similar to :validate => false for Model.save())”
  • Fred Wu

    Fred Wu August 30th, 2010 @ 01:41 AM

    • Fixed some issues and made all the tests pass.
    • Rebased to the master.
  • Jeff Kreeftmeijer

    Jeff Kreeftmeijer October 12th, 2010 @ 09:06 AM

    • Tag cleared.

    Automatic cleanup of spam.

  • Jeff Kreeftmeijer

    Jeff Kreeftmeijer October 13th, 2010 @ 07:09 AM

    • State changed from “new” to “open”
    • Title changed from “[PATCH] :model_callbacks and :validate_callbacks options (similar to :validate => false for Model.save())” to “:model_callbacks and :validate_callbacks options (similar to :validate => false for Model.save())”
    • Tag set to callbacks, patch

    Using the "patch" tag instead of prefixing the ticket title with "[PATCH]" to make sure patched tickets end up in the open patches bin. :)

  • Santiago Pastorino

    Santiago Pastorino February 2nd, 2011 @ 04:30 PM

    This issue has been automatically marked as stale because it has not been commented on for at least three months.

    The resources of the Rails core team are limited, and so we are asking for your help. If you can still reproduce this error on the 3-0-stable branch or on master, please reply with all of the information you have about it and add "[state:open]" to your comment. This will reopen the ticket for review. Likewise, if you feel that this is a very important feature for Rails to include, please reply with your explanation so we can consider it.

    Thank you for all your contributions, and we hope you will understand this step to focus our efforts where they are most helpful.

  • Santiago Pastorino

    Santiago Pastorino February 2nd, 2011 @ 04:30 PM

    • State changed from “open” to “stale”

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

<h2 style="font-size: 14px">Tickets have moved to Github</h2>

The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>

Pages