# Where to validate?

**URL:** <https://www.ruby-forum.com/t/where-to-validate/81973>\
**Category:** Rails\
**Created:** [March 14, 2006, 11:30pm UTC](https://www.ruby-forum.com/t/where-to-validate/81973 "2006-03-14T23:30:03Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![captaffy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/f04885/32.png) [@captaffy](https://www.ruby-forum.com/u/captaffy)\
**Post date:** [March 14, 2006, 11:30pm UTC](https://www.ruby-forum.com/t/where-to-validate/81973/1 "2006-03-14T23:30:03Z")

</div>

class PgmUpdate \< ActiveRecord::Base  
has\_many :pgm\_visits  
…

class PgmVisit \< ActiveRecord::Base  
belongs\_to :pgm\_update  
…

I am trying to make sure that none of the visits in PgmUpdate overlap  
start and end dates. Should this validation exist in PgmUpdate or the  
controller? It seems natural to put them in PgmUpdate, but I must  
force the relationship together because there is no PgmVisit.id until  
the record is saved and I do not want to save it until a later stage.  
Any suggestions?

-John

–  
John S.  
Computing Staff - Webmaster  
Kavli Institute for Theoretical Physics  
University of California, Santa Barbara  
removed\_email\_address@domain.invalid  
(805) 893-6307

---

<div class="post-metadata">

**Author:** ![captaffy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/f04885/32.png) [@captaffy](https://www.ruby-forum.com/u/captaffy)\
**Post date:** [March 15, 2006, 1:06am UTC](https://www.ruby-forum.com/t/where-to-validate/81973/2 "2006-03-15T01:06:34Z")

</div>

You could put the validation on PgmVisit. Just add validation to check  
that  
all other visits (pgm\_update.pgm\_visits) don’t contain dates that  
overlap  
with the one you are trying to save.

Should be straight forward.

-Jonathan.
