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.