I have an Invitee model that has the following fields: id, user_id,
invitation_id, email, created_at, canceled
In the Invitee model I have the following validation:
validates_uniqueness_of :email,
:scope => ‘user_id’,
:message => ‘invitation already sent to that
address’
The model is for an invitation system to invite users to join the
website. I only want each user to send an invitation to an email
address one time. Different users can invite the same email address,
but each individual user can only invite an email address one time. The
“:scope => ‘user_id’” accomplishes this fine for me.
However, when a user cancels and invite, I set the canceled flag to “1”
to signifiy the invitation was canceled. If the invitation is canceled,
I then want to allow that user to send a new invitation to that same
email address again if they want to.
Can I do this with model validations? Right now, my
“validates_uniqueness_of” doesn’t look at the canceled field, and even
if the user cancels an invite they still can’t send an invite again
because they have already invited that email address. Is there some
kind of different option or different use of :scope that I can do to
handle this?