Edward OG wrote:
Sorry to resuscitate this post, but is it possible to do something with
a has_and_belongs_to_many relationship?
e.g. in this case, I want to be able to have the methods
Researcher.projects, Project.principal_investigator, and
class Researcher < ActiveRecord::Base
class Projects < ActiveRecord::Base
has_one :principal_investigator, :class_name => “Researcher”,
:foreign_key => “princ_inv” # A Project can only have one principal
has_many :co_investigator, :class_name => “Researcher”, :foreign_key
=> “co_inv” # Projects can have many co-investigators
Looks to be an interesting problem you are tackling. Being a PI, I’d
love to hear more about your application.
In this particular case, I think you have your models set up
In theory, PIs, co-investigators, and researchers are all people (or
users) who happen to have different roles. The role will be different
on different projects, perhaps you need something like…
class User < ActiveRecord::Base
class Collaboration < ActiveRecord::Base
class Project < ActiveRecord::Base
you could do this with a HABTM table with attributes, but this seems a
little more natural to me, and I can see the collaboration model
becoming more complex.