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?
You’re using the
User#requestsassociation, which has no clue about your conditions onRequest#user.aUser.requests.createbuilds and saves aRequestobject based on any conditions given on therequestsassociation and adds it to the list of associated requests.Sure,
Requesthappens to have auserassociation, but that is never used in your examples.And yes, it leads to weird behavior and inconsistencies:
If you want to enforce it from the Request level using validations, you can do something like: