Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7872915
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T02:21:28+00:00 2026-06-03T02:21:28+00:00

It seems that validates_uniqueness_of :some_field will run on a save even if the some_field

  • 0

It seems that validates_uniqueness_of :some_field will run on a “save” even if the some_field attribute has not changed (if other fields have changed). This seems wasteful, since each validates_uniqueness_of will require a database call. I know I can pass a Proc to validates_uniqueness_of to check whether some_field has changed, and I am considering going through all the validations and doing that wherever possible. What I am wondering is:

1) Is that what people interested in performance generally do with their validations?

2) Why is it not validates_uniqueness_of’s default behavior to check whether the attribute has changed first?

3) Are there good reasons for running such validations on attributes that haven’t changed?

I am using Rails 2.3 (for the moment– we are working on upgrading). I don’t know this is the same situation in Rails 3.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T02:21:31+00:00Added an answer on June 3, 2026 at 2:21 am

    What if someone changed the value in the database directly?

    What if some other (non rails app) app also accesses the database?

    In all above scenarios you will still want that your data be valid, so that your rails application behaves as expected. In case the data was tampered with (by the other app, or in database directly), your rails app throws an error because it doesn’t expect that data.

    Having said that, it is the default behaviour. The default behaviour is generally more restrictive, in order to maintain data validity and minimise scope of errors, omissions, and occasional slips. In case you are worried about performance in your case, maybe your object is being updated very frequently, and you have a lengthy custom validation on a field that isn’t being updated that frequently, and you don’t want to run that validation each time, then it makes perfect sense to customize the default behaviour as you have described in the question.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a model that has two fields, which I will call first_name and
Seems that even after unchecking the option in the PyDev/Debug preferenecs pane to launch
It seems that when a WPF application starts, nothing has focus. This is really
it seems that we will put source ~/.bashrc in our .bash_profile anyway. So why
It seems that when we use form_for @story do |f| then Story has to
I have a Website model, that has a @Required User owner property. This property
I have a form containing a list of input fields that the user populates
I have a Rails app that has a COUNTRIES list with full country names
I am trying to get my UniqueEmail validator working but it seems that my
It seems that in a standard Xcode project, the default target automatically updates the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.