# Conditional Validation: only if a record can be found

**URL:** <https://www.ruby-forum.com/t/conditional-validation-only-if-a-record-can-be-found/168663>\
**Category:** Rails\
**Created:** [May 23, 2009, 6:55pm UTC](https://www.ruby-forum.com/t/conditional-validation-only-if-a-record-can-be-found/168663 "2009-05-23T18:55:37Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![daborg69](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/d9b06d/32.png) [@daborg69](https://www.ruby-forum.com/u/daborg69)\
**Post date:** [May 23, 2009, 6:55pm UTC](https://www.ruby-forum.com/t/conditional-validation-only-if-a-record-can-be-found/168663/1 "2009-05-23T18:55:37Z")

</div>

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
