On Tuesday, July 27, 2004, 8:59:26 PM, Carl wrote:

> I'm still new to ActiveRecord, so forgive me if this is obvious, but
> is it necessary in a relationship like the one below for each table to
> refer to the other?  In this relationship, it would be sufficient for
> the projects table to have a manager_id and it would not be necessary
> for the managers table to have a project_id, or vice versa.  Does
> ActiveRecord require both tables to refer to one another?

This is "obvious" from a database design point of view.  If two tables
have a 1-N relationship, then it's pretty obvious (if you have some
experience in the area) that the N table will refer to the 1 table.
In your case, let's say a project has a single manager, but a manager
can manage multiple projects.  Then you'll have:

  table project:
    project_id
    manager_id
    description
    ...

  table manager:
    manager_id
    ...

It's not feasible for one entry in the manager table to refer to
multiple projects.

I'm pretty confident that David would ensure ActiveRecord works just
fine with the above scenario.  What you have to type in, I'm not sure.
But something like this should do.

  class Project < ActiveRecord::Base
    has_one :manager
  end

  class Manager < ActiveRecord::Base
    has_many :project
  end

Cheers,
Gavin