On Aug 24, 2011, at 4:15 PM, Banjoey wrote:

> We currently use excel to store data that is used by scripts to run
> automated tests for our software. Our project scope is expanding, and
> the excel sheets are no longer adequate to meet our needs (multiple
> people needing to enter test data) so I threw together a simple proof
> of concept and my boss really liked it. In fact, I'm now working on
> setting this thing up to go live as soon as I can get it into a semi-
> working state.
> 
> My current issue is that I have a "patient" model that needs to have
> certain data associated with it. I need a specific number of fields
> for say "Physicians" (I need exactly 5 physicians), in each patient
> record. I know I can do a has_many relationship, but that's not really
> adequate because each of the "physicians" have to be a specific "type"
> of physician. However, all these physicians (though assigned different
> types) will come from the same pool of names. In fact, it is possible
> that the testers may want one physician to serve as all "types".

It sounds like you're looking for a simple belongs_to relation for each of 
them. For concreteness, here's a version with 4 doctor positions:

class Patient < ActiveRecord::Base

  fields do
    name :string
    timestamps
  end

  belongs_to :head_doctor, :class_name => 'Doctor'
  belongs_to :shoulder_doctor, :class_name => 'Doctor'
  belongs_to :knee_doctor, :class_name => 'Doctor'
  belongs_to :toe_doctor, :class_name => 'Doctor'

end

You'll wind up with head_doctor_id, etc fields in the schema. The default Hobo 
behavior for these associations will be to generate a select-one for each, 
which should be really close to what you're looking for.

Things get more complicated if you need to deal with uniqueness, but it sounds 
like that is explicitly *not* required here.

An alternative, more flexible, way would be to define a join model between 
Patient and Doctor and include the "role" as an attribute. However, based on 
your description, it sounds like the five roles are pretty central to the 
process you're describing and therefore unlikely to change without major 
real-world rearchitecturing. Because of that, the join table method seems like 
overkill.

--Matt Jones

-- 
You received this message because you are subscribed to the Google Groups "Hobo 
Users" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/hobousers?hl=en.

Reply via email to