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 8820177
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T05:32:39+00:00 2026-06-14T05:32:39+00:00

I am having a very strange problem in Rails. I am using update_attributes on

  • 0

I am having a very strange problem in Rails. I am using update_attributes on a Parent Object to update all the children objects. The children objects have (custom) validation and indeed this works ok, meaning that if I give wrong values the validation trigger and I get an error back.

Now I am in a strange situation where one of the model is invalid in the database (let’s not question why, let’s just say I can go in the DB and run some SQL to make the model invalid). If I go in my app I can see the invalid values and this is fine. I fix the values and save again and I can see, stepping in the ruby code that the validation is called also BEFORE saving the new values, meaning that I will get an error and Rails will never execute the SQL to actually update the values to the correct ones.

I hope the above makes sense. Do you have any idea or do you think there is something I am overlooking?

SOLUTION:

What was happening was that a many-to-many relationship was validating the existing DB data before being replaced by the new data. Basically the structure was like this:

class User
    has_many :user_permissions
    has_many :permissions, :through => :model_permissions

class Permission
    has_many :user_permissions
    has_many :users, :through => :user_permissions

class UserPermission
    belongs_to :user
    belongs_to :permission
    validates_associated :user       # THIS was causing the problem
    validates_associated :permission # and THIS as well

I simply removed the validates_associated directive, since I am validating the linked records independently anyway.

  • 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-14T05:32:40+00:00Added an answer on June 14, 2026 at 5:32 am

    Well, Rails does run your validation prior to writing the data to the database (please refer to Active Record callback sequence), so having validation errors means that some piece of the model you are trying to save is not valid. It might an associated model containing errors with the validation turned on or just some missing part – in any case, just have a look at what are the errors you are getting.

    In case (let’s no question why either 🙂 you want to skip validation – you are open to choose from #update_attribute (to update just one attribute), calling #save(false), using +udpate_all method of the model class or even go down to ActiveRecord::Base.connection.execute – none of these will ever bother you with validation errors 🙂

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

Sidebar

Related Questions

Im having a very strange problem, i have a complicated view that returns incorrect
I'm having a very strange problem. I'm using dfs-datastores Pail abstraction to write data
I am having a very strange problem in a simple program and have been
I am having a very strange problem, I have this file for User#show view:
I have a very strange problem. (fyi - I'm using forms authentication and manually
I'm having a very strange problem with my custom listview. This Listview shows a
I am having a very strange problem inserting values into my mysql database, using
I am having a very strange problem with an ASP.Net project using an Entity
I'm having a very strange problem. I'm using Visual Studio 2010 Ultimate on Windows
I'm having a very strange problem. I'm getting a collection of Rails ActiveRecord models

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.