NUBIC/surveyor — Issue #277: Support storing, querying on arbitrary properties for Survey
Author: rsutphin
Created: 2012-02-27 21:56:44+00:00
State: open
Labels: Data model, Feature Request, ncs

An applications may contain more than one survey, or multiple versions of the same survey. Such applications may need to select surveys based on or report about surveys taken using more information than is allowed for in the Survey model. Some examples for NCS instruments include the version of the instrument definition on which the survey is based or the source instrument's type code.

Such applications have the option of defining additional attributes on the Survey model. Then they face another question: how to populate these additional attributes? If they are related to how the survey is defined (as with the NCS examples), it would make sense to keep them with the corresponding survey. Unfortunately the survey DSL is not extensible, so this is not an option.

While making the survey DSL extensible might be a good idea later, for now I propose adding a set of arbitrary properties to the Survey model. These could be defined in the DSL:

```ruby
survey 'INS_BIO_Sample' do
property :instrument_version, '2.0'
property :instrument_type_code, '7'

section 'Start' do
# ...
end
end
```

Then you could read them from a survey instance:

```ruby
s = Survey.first
s.properties[:instrument_version] # => "2.0"
```

Or query for matching surveys:

```ruby
Survey.find_by_property(:instrument_version, '2.0').collect(&:title) # => ['INS_BIO_Sample']
```