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 Smilanick Computing Staff - Webmaster Kavli Institute for Theoretical Physics University of California, Santa Barbara jsmilani@kitp.ucsb.edu (805) 893-6307 -------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060314/f73ebc5b/attachment.html
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. On 3/15/06, John Smilanick <jsmilani@kitp.ucsb.edu> wrote:> > 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 >-------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060315/236834b6/attachment.html