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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T23:38:41+00:00 2026-05-22T23:38:41+00:00

I have this model called Request , which belongs_to a User . class Request

  • 0

I have this model called Request, which belongs_to a User.

class Request < ActiveRecord::Base    
  belongs_to :user, :conditions => "can_make_requests = t"
end

The User model has a boolean field in its schema named can_make_requests, but for some reason, when I try

aUser.requests.create

when aUser has can_make_requests as f, it still works (aUser.requests.first returns the newly made request). Does anyone know what the issue is?

  • 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-22T23:38:42+00:00Added an answer on May 22, 2026 at 11:38 pm

    You’re using the User#requests association, which has no clue about your conditions on Request#user.

    aUser.requests.create builds and saves a Request object based on any conditions given on the requests association and adds it to the list of associated requests.

    Sure, Request happens to have a user association, but that is never used in your examples.

    And yes, it leads to weird behavior and inconsistencies:

    >> user = User.create(:can_make_requests => false)
    => #<User id: 3, can_make_requests: false>
    >> request = user.requests.create
    => #<Request id: 2, user_id: 3>
    >> request.user
    => nil
    >> user.requests
    => [#<Request id: 2, user_id: 3]
    

    If you want to enforce it from the Request level using validations, you can do something like:

    class Request < ActiveRecord::Base
      validates :user, :presence => true
      validate :user_can_make_requests
    
      def user_can_make_requests
        errors[:user] << 'cannot make requests' if user && !user.can_make_requests?
      end
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this Task model: class Task < ActiveRecord::Base acts_as_tree :order => 'sort_order' end
I have a class in my domain model called JobPlan this class is stored
Let's say I have a model class called Project, but instead of this: class
I have a model that holds user address. This model has to have first_name
I'll just jump right into it. I have a model called Request which I
So I have a method in a reservation model called add_equip. This method does
I have this model in django: class JournalsGeneral(models.Model): jid = models.AutoField(primary_key=True) code = models.CharField(Code,
Okay so I have this mode: class Posts(db.Model): rand1 = db.FloatProperty() #other models here
I have a model which contains a ManyToMany to User to keep track of
I'm using ASP.NET MVC and I have a model class which represents a peice

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.