I have a model User
, which has_many
Profile
. I also have Report
model, which belongs_to
Profile
.
How can I make sure that one user has only one report? Something like
class Report
validate_uniqueness_of profile_id, scope: :user
end
would be great, but of course it doesn't work. (I don't want to attach user field to Report, because it mixes up ownership chain).
Just to give you an idea on how to implement custom validations. Check this