NUBIC/surveyor — Issue #275: Eliminate Response#response_set_id presence validation
Author: yipdw
Created: 2012-02-27 17:28:48+00:00
State: open
Labels: Data model, Feature Request, Validations

The presence validation on `Response#response_set_id` introduced in 05034182be24f01b9960ecc19cbf9e452bc65e43 makes it impossible to write code like this under ActiveRecord 3.1:

```ruby
rs = ResponseSet.new(:survey_id => survey_id)
rs.responses.build(...)
rs.save
```

because the ResponseSet will not have been saved at the time when Response's validations run. (This pattern appears in some code being written for the National Children's Study.)

However, building a ResponseSet and its responses in this fashion can be done without violating referential integrity, which can be demonstrated by eliminating the validation under discussion, adding appropriate not-null and foreign key constraints on `Response#response_set_id` in a database that supports them (e.g. PostgreSQL), and executing the above code. Therefore, I think that the presence validation is an unnecessary inhibition, and ask that it be eliminated or made optional.