Say we have the models Patient and PatientRawData (with a belongs_to association to Patient).
Is it possible to create new records (without saving them in database), associate them, and finally save them in the database?
Something like this:
patient = Patient.new(:name => 'John', :age => 34)
rawtext = PatientRawText.new(:rawtext => 'My name is..')
patient.rawtext = rawtext
patient.save!
The reason I want to do this, is that in my real case scenario there might more complex models/associations and I would prefer to not have partial things in the database in case of an exception.
For this reason I prefer to build whatever complex thing I want, and as a final step to store the whole thing in the database.