# HABTM, and complex validation

**URL:** <https://www.ruby-forum.com/t/habtm-and-complex-validation/136942>\
**Category:** Rails\
**Created:** [May 7, 2008, 4:18pm UTC](https://www.ruby-forum.com/t/habtm-and-complex-validation/136942 "2008-05-07T16:18:59Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![bartz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/3ab097/32.png) [@bartz](https://www.ruby-forum.com/u/bartz)\
**Post date:** [May 7, 2008, 4:18pm UTC](https://www.ruby-forum.com/t/habtm-and-complex-validation/136942/1 "2008-05-07T16:18:59Z")

</div>

Hey gang,

Pretty complicated question, but I’ll try my best.  
I’m building an app in which the user can enter a Show. A Show has\_many  
items, and each Item has and belongs to many People. So, a person can  
appear in many items (think interviews for instance) in many shows. Easy  
so far, here comes my headache.

In the item form, I’d like to add people, if those people aren’t in  
another item a couple of days around that item. So say person A is in  
item X tomorrow, and a user tries to add item Y with person A also for  
tomorrow, I’d like to show a warning for that.

I’m using Railscasts’ complex form trick for this all  
([#75 Complex Forms Part 3 - RailsCasts](http://railscasts.com/episodes/75)), and added an auto complete handler  
to find a Person based on the name entered in the field.  
Somehow I need to add a validation rule to check for recent shows  
somewhere, but for that I need a Person and an Item, meaning I can’t put  
it in the Person model and neither in the Item model.

I’m kinda stumped here, so if anyone has an idea, please help me out!

cheers,  
bartz
