- Survey: the primary table that defines a survey project
- SurveyQuestion: object to hold a specific question mapped to a survey
- SurveyResponder: the person that is answering the survey questions
- SurveyResponse: the recorded answers that the reponder enters
Grails/GORM Implementation:
I began by generating the Survey and Survey question domain classes and basic validation tests. Next was to create the SurveyReponder and SurveyResponse classes. The implementation was straight forward, but I had to fiddle with the domain class definitions to get hibernate to understand my intent. Just a matter of specifically defining class references in dependent models rather than depending on the 'belongs_to' and 'has_many' declarations.
Datasets and Loaders (Fixtures):
Unlike Rails, Grails doesn't use fixtures for test data. Lucky for me I have a Grails enhancement the solves this based on a sandbox proposal from the Grails guys. So I generated the dataset loader classes using: grails create-dataset [domain]. This creates the following:
- a DataLoaderBootStrap class in grails-app/conf/ (unless it exists)
- a DomainDataset class in src/groovy/datasets
- a set of random data to be loaded
> grails create-dataset survey
> ...
> file grails-app/conf/DataLoaderBootStrap.groovy exists...
> created file src/groovy/datasets/SurveyDataset.groovy
>
The SurveyDataset class looks like this:
class SurveyDataset {
dataset = {
def set = [
[ name:'879',description:'510',email:'680' ],
]
return set
}
load() {
dataset().each { data ->
obj = new Survey( data )
obj.save()
}
}
}