Assume that model/table "party" contains a column "party_type" and consider that "party_type" is value constrained to those values in model/table "system_values" having EAV columns of table_name, table_column_name, value_as_char and having a composite index "system_value_lookup_idx" defined as: add_index(:system_values, :table_name, :table_column_name, :value_as_char, { :name => :system_value_lookup_idx, :unique => true } Is it advisable to place a validation lookup into the "party" model? Should one do this using the generic validate method or is there a better way? Is the following a valid and useful approach? class Party << ActiveRecord::Base validate :check_party_type def check_party-type errors.add-to_base("Party type #{self.party_type} is not found.") unless SystemValue.exists?(:table_name => :parties, :table_column_name => :party_type, :value_as_char => self.party_type.to_s ) end Comments most welcome. -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
James Byrne wrote:> Comments most welcome.Anyone? -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
James Byrne wrote:> > class Party << ActiveRecord::Base > > validate :check_party_type > > def check_party-type > errors.add-to_base("Party type #{self.party_type} is not found.") > unless > SystemValue.exists?(:table_name => :parties, > :table_column_name => :party_type, > :value_as_char => self.party_type.to_s > ) > end > > Comments most welcome.Your approach is perfectly valid according to me, the only other option I can think of is to have a db trigger that checks the field against another table on insert but then you will not get the nicely formated error string that you are producing now. hth ilan -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---