I have this code in my model:
validates :user, presence: true, uniqueness: {scope: :project}
Individual validators, availability and uniqueness, each one works fine if there is no other. But if they are both present, as indicated above, the presence validator stops working. When I try to save an object with a null user, instead of getting a normal save error, I get an exception:
NoMethodError: undefined method 'attributes' for nil: NilClass from / usr / local / lib / ruby / gems / 2.0.0 / gems / activerecord-4.0.2 / lib / active_record / validations / uniqueness.rb: 56: in `build_relation ''
Is this a bug in ActiveRecord or am I doing something wrong?
source
share