There are several approaches (I think in the Hibernate project there are better explanations from a OO point of view), but I can think of the following:

1) Association 'dispatcher' table

Ownership
-------------
Row_id
Owner_type
Family_id
Car_id
...
etc

With this approach, as you say, we add columns for every kind of owner to the Ownership table. It's like a "dispatcher" table, and of course, if the number of possible owners is very large it drags down (though a range of 1-15 owner types would be acceptable, IMO)

Or... we could do it backwards:

2) Foreign keys on owner tables

Family
--------
Id
Name
car_id

Company
------------
Id
Name
car_id

Car
----
Id
Name

This doesn't define an "ownership" per se, but allows for lots of owner types.
The "owners for this car" query gets a little complicated, of course.

There could be other approaches, of course. Weak foreign keys also comes to mind (a single Owner table with "table" and "id" properties).

--
Ing. Leonardo Quijano Vincenzi
Director Técnico
DTQ Software


Patrick Casey wrote:
        How would an association table help me (assuming I wanted to enforce
foreign key integrity there as well)?

        Family
        ------
        Id
        Name

        Company
        -------
        Id
        Name

        Cars
        -------
        Id
        Name

        Ownership
        --------
        Row_id
        Owned_by (either company or family)
Owner_id Car_id

        Wouldn't owner_id run into the same problem of being a dual FK
relationship? I suppose I could do:

        Ownership
        --------
        Row_id
        Family_id (might be null)
        Company_id (might be null)
        Car_id (fk --> cars(id))

        But then as the number of potential car owning tables expands, my
association table gets arbitrarily large, doesn't it?

        Or am I missing something obvious here?

        --- Pat




---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to