Changeset 689


Ignore:
Timestamp:
Jul 21, 2010, 4:52:12 PM (6 years ago)
Author:
keesvb
Message:

finally added the uniqueness constraint for sample names. it's real simple after all now we have the belongsTo

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/grails-app/domain/dbnp/studycapturing/Sample.groovy

    r667 r689  
    22
    33import dbnp.data.Term
    4 import dbnp.data.Ontology
    54
    65/**
     
    4443                material(nullable: true)
    4544
    46                 // TODO: Write a validation method that checks if the externalSampleId (currently defined as name)
    47                 // is really unique within each parent study of this sample.
    48                 // Maybe this could also be a constraint, but we might run into trouble creating new Sample objects in e.g. the create wizard.
    49                 // To be checked.
     45                // Checks if the externalSampleId (currently defined as name) is really unique within each parent study of this sample.
    5046                // This feature is tested by integration test SampleTests.testSampleUniqueNameConstraint
    51 
    52                 /*name(validator: { fields, obj, errors ->
    53                         def error = false
    54 
    55                         if (fields) {
    56                                 // Search through all study
    57                                 if (obj.parent.samples.findAll({ it.name == fields}).size() != 1) {
    58                                         errors.rejectValue(
    59                                                 'name',
    60                                                 'sample.name.NotUnique',
    61                                                 ['name',fields] as Object[],
    62                                                 'The sample name is not unique within the study'
    63                                         )
    64                                 }
    65                         }
    66                         else {
    67                                 // If no value for name is specified, the sample should not validate
    68                                 error = true
    69                         }
    70 
    71                         return (!error)
    72                 })*/
     47                name(unique:['parent'])
    7348        }
    74 
    75         /*static def getParentStudies() {
    76                 Study.findAll {
    77                         it.samples.findAll {
    78                                 it.name == this.name
    79                         }
    80                 }
    81         }*/
    8249
    8350        static getSamplesFor( event ) {
Note: See TracChangeset for help on using the changeset viewer.