-1

我想在我的接口表中禁止 5 列的非唯一组合。例如以下列:

:case_number, :client_name, :matter_name, :country, :engagement_code,
these rows should be allowed:
1,1,1,1,1
1,1,1,1,1
1,1,1,1,1

and these rows should not be allowed:
1,2,1,1,1
2,3,1,1,1
1,1,4,5,1
4

1 回答 1

0

我想到了:

在模型中添加:

validate :non_unique_combination?

def non_unique_combination?                                     
    if EvidenceImportInterface.count > 0 and 
       !(EvidenceImportInterface.exists?(:case_number => self.case_number,
                                        :client_name =>  self.client_name,
                                        :matter_name =>  self.matter_name,
                                        :country =>  self.country,
                                        :engagement_code =>  self.engagement_code))                                                 
        errors.add(:case_number,'Combination not valid')
    end 
end
于 2012-09-27T18:02:36.963 回答