Conditional Validation: only if a record can be found


#1

Hello!

I have a guestlist page which lists tickets and a user can attache a
guest to each ticket by using an auto complete form.

If each ticket has a guest attached, then the guestlist is ‘full’

I have this rule in my controller and I want to turn it into a
validation in the model. Any ideas?

(sudo code)

if Ticket.find(first, condition => guestlist_id = ? and guest_id IS
NILL)
attach guest
else
display ‘guestlist is full’
end

Thanks for your help

Scott