Forum: Ruby on Rails Where to validate?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
John S. (Guest)
on 2006-03-15 00:30
(Received via mailing list)
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
Jonathan V. (Guest)
on 2006-03-15 02:06
(Received via mailing list)
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.
This topic is locked and can not be replied to.