Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

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

#5418

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.

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

State: stale
Milestone: none
Assigned to: nobody
Importance: Low

Activity

  1. Fred Wu
    Fred Wu

    Thoughts anyone?

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

    August 24th, 2010 @ 08:51 AM

  2. Neeraj Singh
    Neeraj Singh
    • Importance changed from to Low

    @Fred are all the tests passing?

    August 24th, 2010 @ 11:57 AM

  3. Fred Wu
    Fred Wu

    Yes, they certainly are. :)

    August 24th, 2010 @ 12:47 PM

  4. Fred Wu
    Fred Wu
    • 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.
    

    August 24th, 2010 @ 11:26 PM

  5. Fred Wu
    Fred Wu
    • 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())

    August 25th, 2010 @ 02:49 AM

  6. Fred Wu
    Fred Wu
    • Fixed some issues and made all the tests pass.
    • Rebased to the master.

    August 30th, 2010 @ 01:41 AM

  7. Jeff Kreeftmeijer
    Jeff Kreeftmeijer
    • Tag cleared.

    Automatic cleanup of spam.

    October 12th, 2010 @ 09:06 AM

  8. Jeff Kreeftmeijer
    Jeff Kreeftmeijer
    • 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. :)

    October 13th, 2010 @ 07:09 AM

  9. Santiago Pastorino
    Santiago Pastorino

    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.

    February 2nd, 2011 @ 04:30 PM

  10. Santiago Pastorino
    Santiago Pastorino
    • State changed from open to stale

    February 2nd, 2011 @ 04:30 PM