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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T04:58:06+00:00 2026-05-24T04:58:06+00:00

With Rails 3.1, I have: class Status < ActiveRecord::Base has_many :participations, :dependent => :destroy

  • 0

With Rails 3.1, I have:

class Status < ActiveRecord::Base
  has_many :participations, :dependent => :destroy
  has_many :users, :through => :participations

  validates :users, :presence => true
end

In my unit test, I do:

user = User.create(:name => "Bob")
status1 = Status.create(:description => "available")
user.statuses << status1

and get:

ActiveRecord::RecordInvalid: Validation failed: users can’t be blank

but, if instead of the last line I do:

status1.users << user

it works fine.

Why does the validation get triggered for:

user.statuses << status1

UPDATE:

the test in full

 test "Return all statuses associated with the manager" do
    manager = Manager.create(:email => "foo@bar.com", :password => "password", :password_confirmation => "password")

    workshop = Workshop.create(:name => "Bob Autos")
    manager.workshop = workshop
    manager.save

    user = User.create(:name => "a customer")

    workshop.users << user

    status1 = Status.create(:description => "Car is ready")
    status2 = Status.create(:description => "problem with exhaust")
    status3 = Status.create(:description => "parts delivered")

    user.statuses << status1
    user.statuses << status2

    assert_equal([status1, status2], manager.statuses)

    user.statuses << status3

    assert_equal([status1, status2, status3], manager.statuses)
  end
  • 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-05-24T04:58:07+00:00Added an answer on May 24, 2026 at 4:58 am

    The validation is on Status, not on User. A model’s validation is only triggered when that model is updated, and you didn’t actually update the User model (since statuses is an association, not a field).

    If you want validation on one object to trigger validation on another, you should use validates_associated:

    class Status
      validates_associated :users
    end
    

    (On a related note, though, why does a Status have many users? Seems like a Status should only be on one user.)

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

Sidebar

Related Questions

I have a the following rails models: class Release < ActiveRecord::Base has_many :release_questionnaires, :dependent
I have a simple has_many through relationship set up: class Tag < ActiveRecord::Base has_many
I have a rails model that looks something like this: class Recipe < ActiveRecord::Base
In a Rails app I have Sales and Salespeople: class Sale < ActiveRecord::Base belongs_to
Rails 3.0.3 and Ruby 1.9.2 I have the following class class item < ActiveRecord::Base
In a Rails 3 app I have the following: class Kase < ActiveRecord::Base state_machine
In my Rails 2.3.2 app I have 2 models: class Post has_many :approved_comments, :class_name
I need to set an HTML class to this rails select and i have
For example I have the following migration class AddStatusField < ActiveRecord::Migration def self.up add_column
In my Rails 3 project I have the following code for My controller: class

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.